PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Do I need to manually release all resources?

Do I need to manually release all resources at the end of the program by calling apropriate free() method of every object?

Or this is done automatically?
Nomad,

It is not necessary to call the apropiate free method when you program finishes. It's a good practice but the truth is that when the process ends, all the memory allocated for that process it`s liberated.
You don`t have to concern about this memory usage because the SO handles it. But, ONLY IF YOUR PROGRAM ENDS, if not, this memory will not be free until you call the method.

I hope it`s usefull

Best Regards
Hi, Matias!

Yes, it was helpful.

And I want to know some more on this topic.
Is that actions that do free() method, done in every object's destructor or not?
Hi Nomad,

No, they are not. You have to call them manually. It was a design decision, and something that you usually do in that way in C++ frameworks. And I tell you why:
If you pass an object (for example a Surface) to a method or function, not a pointer to it, but the object, or a reference to it, something like this:

Code:

Surface surface;
surface.create(TEXT("image.png");
useMySurface(surface);


If the free() method is being called by the destructor, then you could not use the surface instance after you call "useMySurface" function, because when you reach the end of that function, the destructor of the parameter copy of surface will be called, and as they share the same buffer, this buffer will be deallocated, and the original surface instance can not be used anymore.
Now, this (implementing a free() method on every GledPlay class) is not the only solution to the problem, but we though it was the better one.

Best Regards,
Sergio.