Click here to Skip to main content
15,899,026 members
Home / Discussions / C#
   

C#

 
GeneralRe: virtual list? Pin
User 988517-Dec-02 6:16
User 988517-Dec-02 6:16 
GeneralRe: virtual list? Pin
leppie17-Dec-02 6:37
leppie17-Dec-02 6:37 
GeneralRe: virtual list? Pin
User 988517-Dec-02 7:00
User 988517-Dec-02 7:00 
GeneralRe: virtual list? Pin
leppie17-Dec-02 7:09
leppie17-Dec-02 7:09 
GeneralSystem.TypeInitializationException error Pin
$iva16-Dec-02 19:18
$iva16-Dec-02 19:18 
GeneralGarbage Collection + threading question Pin
Radoslav Bielik16-Dec-02 12:27
Radoslav Bielik16-Dec-02 12:27 
GeneralRe: Garbage Collection + threading question Pin
Paul Ingles16-Dec-02 14:17
Paul Ingles16-Dec-02 14:17 
GeneralRe: Garbage Collection + threading question Pin
Jeff J16-Dec-02 20:42
Jeff J16-Dec-02 20:42 
There is no delete operator, although if the class implements a Dispose() method, you can call that instead (some classes, such as streams, call Dispose() when their Close() method is called). Generally you do not have to bother, since it will get called eventually anyway. Even so, it would likely be quite some time before the GC sees any need to actually deallocate your object, unless a serious amount of memory has been used up, and space is tight. You are correct that objects are not disposed of until all references are gone, yet the GC is normally in no hurry.

Since the GC heap is fairly large to begin with, there is little gained by it hurrying to deallocate objects, since the heap itself will not normally shrink anyway. Small and moderate sized apps may never use all of that heap, so actually nothing is gained by quick destruction. Only when there is high heap-memory demand is there a need to destroy unused stuff, to make room for yet more objects.

rado wrote:
Let's suppose, that after the thread is started, the SomeDummy variable is no longer stored, and therefore this instance of the DummyClass class is no longer referenced. What will happend?

I hope I'm interpreting correctly here. SomeDummy has to be stored in order to create the ThreadStart object (otherwise an exception is thrown), and since DummyStart() is referenced in that constructor, the reference will remain, even if SomeDummy had a Dispose() method that was called, and it was set to null after calling thrSomeThread.Start().

rado wrote:
Will the CLR keep track of this instance, and will the garbage collection find out that it is no longer needed when the thread has finished, or will it exist along with the thread, until the instance of the Thread class (which is thrSomeThread in this case) will be referenced?

Yes to both cases. The GC will eventually find out if the object instance is no longer needed after the thread is done. Also, the object will exist along with the thread, because the thread itself references the SomeDummy object it was started with. In fact, the lifetime of the thread is determined by how long the DummyStart() call lasts. When DummyStart() ends, so does thrSomeThread. SomeDummy will stay around for at least that long (and possibly longer). I hope my explanation made some sense...

Cheers
GeneralRe: Garbage Collection + threading question Pin
Daniel Turini17-Dec-02 7:01
Daniel Turini17-Dec-02 7:01 
GeneralRe: Garbage Collection + threading question Pin
Radoslav Bielik18-Dec-02 6:46
Radoslav Bielik18-Dec-02 6:46 
GeneralProblems while developing an Explorer bar in C# Pin
Arun Bhalla16-Dec-02 12:16
Arun Bhalla16-Dec-02 12:16 
GeneralWin32 Search features Pin
David23g16-Dec-02 11:46
David23g16-Dec-02 11:46 
GeneralRe: Win32 Search features Pin
Jeff J16-Dec-02 19:26
Jeff J16-Dec-02 19:26 
GeneralListView Icon Selection Pin
Jonathan Austin16-Dec-02 11:04
Jonathan Austin16-Dec-02 11:04 
GeneralRe: ListView Icon Selection Pin
Jonathan Austin16-Dec-02 11:21
Jonathan Austin16-Dec-02 11:21 
GeneralRe: ListView Icon Selection (I butchered it) Pin
Jonathan Austin16-Dec-02 12:25
Jonathan Austin16-Dec-02 12:25 
GeneralRe: ListView Icon Selection (I butchered it) Pin
Jeff J16-Dec-02 19:03
Jeff J16-Dec-02 19:03 
GeneralRe: ListView Icon Selection (I butchered it) Pin
Jonathan Austin17-Dec-02 8:08
Jonathan Austin17-Dec-02 8:08 
Generalquestion on string and encryption sorta Pin
jtmtv1816-Dec-02 9:51
jtmtv1816-Dec-02 9:51 
GeneralRe: question on string and encryption sorta Pin
jtmtv1816-Dec-02 10:45
jtmtv1816-Dec-02 10:45 
GeneralRe: question on string and encryption sorta Pin
Rob Graham16-Dec-02 11:15
Rob Graham16-Dec-02 11:15 
Questionhelp require? Pin
imran_rafique16-Dec-02 6:49
imran_rafique16-Dec-02 6:49 
AnswerRe: help require? Pin
Andres Manggini16-Dec-02 12:13
Andres Manggini16-Dec-02 12:13 
GeneralRe: help require? Pin
imran_rafique16-Dec-02 12:36
imran_rafique16-Dec-02 12:36 
GeneralWindows Form Control hosted in IE Pin
LJMorsillo16-Dec-02 4:34
LJMorsillo16-Dec-02 4:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.