B
Boris
I am having really tough time finding anywhere on the web
concrete explanation (if any) of how Garbage Colletor
decided for C++ managed objects when object is ready to be
released, and why? Refer to simple example below with
questions inside comments.
__gc public class MyGCClass
{
...
}
void main()
{
simple_unmanaged_function();
}
void simple_unmanaged_function()
{
int x = 0;
MyGCClass* obj = new MyGCClass();
obj->DoSomething();
// Can GC release the MyGCClass instance
// at this point, if it is not being used
// until the end of the function?
// Must GC postpone collecting the instance
// until obj reference to goes out of
// of scope? i.e. for function to return
// What if different optimizations are
// set in "project"->"Property"->
// "c/c++"->"Optimizations"?
//
x = 5;
// Is this (set to NULL) necessary to
// mark obj as not referencing and
// available for GC?
// Or going out of scope is sufficient?
// obj = NULL;
// Seems to work without setting obj to NULL,
// but I just want to know what is good
// practice and why...
}
Thank you,
-Boris
concrete explanation (if any) of how Garbage Colletor
decided for C++ managed objects when object is ready to be
released, and why? Refer to simple example below with
questions inside comments.
__gc public class MyGCClass
{
...
}
void main()
{
simple_unmanaged_function();
}
void simple_unmanaged_function()
{
int x = 0;
MyGCClass* obj = new MyGCClass();
obj->DoSomething();
// Can GC release the MyGCClass instance
// at this point, if it is not being used
// until the end of the function?
// Must GC postpone collecting the instance
// until obj reference to goes out of
// of scope? i.e. for function to return
// What if different optimizations are
// set in "project"->"Property"->
// "c/c++"->"Optimizations"?
//
x = 5;
// Is this (set to NULL) necessary to
// mark obj as not referencing and
// available for GC?
// Or going out of scope is sufficient?
// obj = NULL;
// Seems to work without setting obj to NULL,
// but I just want to know what is good
// practice and why...
}
Thank you,
-Boris