https://wiki.archlinux.org/index.php/Co … bumping%22
Closing.
]]>I recently got back into C++ coding and kinda assumed the OS handles de-allocation or freeing the heap when a program is terminated. So should I bother tracking down those bytes that were never de-allocated? if so how should I go about this? Luck for me I just very recently got back into C++ & remember mostly what I've done & I've not ran any fancy/complicated or big programs (less than 300 lines of code). I've opened, ran and terminated this program probably only 3-4 times and it contains like one or two pointers in total.
I can hop on my computer and paste the code, it's just a fun project that administers a "big five" personality test. Very basic cout then cin some value then some basic math for score calculations.
]]>Read about std::auto_ptr, boost::shared_ptr, boost::intrusive_ptr,
boost::weak_ptr and boost::shared_array to see what options are available to
you.
Btw, this is valid for more than just memory allocation. Generally, you should
make sure every resource you acquire from the system is properly released when
you're done with it, even if exceptions occur.
void func( mystruct & foo )
{ ..}
mystruct bar(construct,parameters);
func(bar);
2: If your return a 'new' pointer, it will work just fine no matter who has it. But someone, somewhere, must delete it.
]]>void func(mystruct *foo) { /* do stuff */ }
...
func(new mystruct(constructor params));
...
Is the struct deallocated automatically or do I have to deallocate it manually when I don't need it anymore?
Also, if I
return new mystruct(constructor params);
will that pointer get dereferenced and not work?