Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

General garbage callection question.

Status
Not open for further replies.

vladibo

Programmer
Sep 14, 2003
161
CA
When I have some data to keep, like ID,NAME, DATE, when shall I use Structs and when garbage callected object? Shall I destroy structs if I use them?

Thanks,
vladi
 
It depends on how you declare your struct. If you

myStruct* pMyStruct = new myStruct;
you must clean it up yourself by calling
delete pMyStruct;

If you

{
myStruct ms;
...
}

when it goes out of scope it cleans itself up.

If your struct allocates memory, its destructor should handle the deletion.

Matt
 
But if it is inside garbage collected (__gc) class shall I clean it then?
 
you can call delete for __gc classes, but it will do quite nothing. The destructor will be called, but the object will not be destroyed. So, you should do nothing to eliminate garbage.

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top