When and how is an object deleted? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

When and how is an object deleted?

7th Jul 2016, 9:08 PM
Awni
Awni - avatar
6 Answers
+ 3
// An example to show 'Dispose' ... { ... // We call constructoe to create an object TextBox myText = newTextBox; ... // We use the object myText.Text = "Hello!"; ... // We no longer need it myText.Dispose(); ... } ... // Hope it helps
8th Jul 2016, 12:39 PM
Albert Gullbee
+ 1
Objects are deleted when the block in which the object is created is ended with `}´ or the terminator is called. The terminator has the name of class preceeded by `~´. In C# Dispose method does it.
8th Jul 2016, 8:06 AM
Albert Gullbee
+ 1
If an object is disposable you can call the method to delete it before you reach the end of block
8th Jul 2016, 12:33 PM
Albert Gullbee
0
could u show me an easy example of how dispose work?
8th Jul 2016, 9:55 AM
Máté Lencsés
Máté Lencsés - avatar
0
helped me a lot! thanks dude!
8th Jul 2016, 1:05 PM
Máté Lencsés
Máté Lencsés - avatar
- 1
do you call the dispose method for the object itself or just call the dispose and it clears up?
8th Jul 2016, 9:55 AM
Máté Lencsés
Máté Lencsés - avatar