Original Post
🔒 Locked
C++ Memory
Advertisement
If it is a local variable in a function then the memory for it is "released" in the same way as any other local variable is. C++ is smart enough to call it's destructor before it does so.
If it's a global then the same happens then the program exits. This is your situation. You have nothing to fear as it isn't a pointer to a class.
FYI, if it's a member of a class then it's the same as the first paragraph except the the timing is when the class is released. Remember it's not when destructed.
It's the same as any other variable in respect to memory used because it's memory is statically "allocated" from the heap. That is, the programs' heap pointer is moved to give room for it. (I think that is the right terminology)
Garbage collection is only an issue for specifically allocated memory, eg. use of "malloc/calloc" and "new".
EDIT: reworded
R
--------------------------------------------------------------------------
There is no point in flaming if you've merely poured fuel on your own head
[edited by - RowanPD on April 1, 2004 7:55:44 AM]
If it's a global then the same happens then the program exits. This is your situation. You have nothing to fear as it isn't a pointer to a class.
FYI, if it's a member of a class then it's the same as the first paragraph except the the timing is when the class is released. Remember it's not when destructed.
It's the same as any other variable in respect to memory used because it's memory is statically "allocated" from the heap. That is, the programs' heap pointer is moved to give room for it. (I think that is the right terminology)
Garbage collection is only an issue for specifically allocated memory, eg. use of "malloc/calloc" and "new".
EDIT: reworded
R
--------------------------------------------------------------------------
There is no point in flaming if you've merely poured fuel on your own head
[edited by - RowanPD on April 1, 2004 7:55:44 AM]
The destructor will be called when the program exits. If you want to see when, add some print debugging to the destructor. Anyway, this should not be a serious problem since the OS will clean up every allocation the program made as long as you didn''t deliberately hide it ;-)
If you want more control, create objects locally (it''s easier to see the scope then). For even more control, you can use the new operator which should make it more "Java-like":
You''ll have to use the dereferencing operator to access attributes or methods and make sure you clean up properly with
when you''re done with the object since C++ does not have garbage collection.
If you want more control, create objects locally (it''s easier to see the scope then). For even more control, you can use the new operator which should make it more "Java-like":
Player *play = new Player;
You''ll have to use the dereferencing operator to access attributes or methods and make sure you clean up properly with
delete play;
when you''re done with the object since C++ does not have garbage collection.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement