Page 1 of 1

PostPosted: Tue Dec 09, 2003 2:45 pm
by Manoj
Hi Joe,

I am worried about resource leaks that exist in many C/C++ programs.
As you may know lots of APIs provide 'sandwich' methods, such as :

openSomething() closeSomething()
loadResource() destroyResource()
createRes() deleteRes()
etc.

As a PocketC/PToolBox programmer, do I need to worry about such resource issues? Or does PalmOS runs a garbage collector similar as in Java.

I am worried that if I load a Form or a bitmap when should I Free it [Fctl(FREE)]
This is trickier for me because there are no hooks or specific lifecycle events when the destructors for acquired resources would run.

For instance, the the user may open a DB, read data and then turn off the PDA. What happens to the open DB? The app was not cleanly shutdown. is the DB still open?

So, is it advisable to open and close the DB for each method call? [That would be expensive]
Or is it taken care of by the OS.
Similar question arises for Loading and Freeing of Forms and Arrays.

How do we go about it. Please advice.

PostPosted: Tue Dec 09, 2003 5:42 pm
by jstadolnik
All resources are automatically cleaned up (the PToolboxLib handles this), all dynamic memory is freed, and all a databases are closes when an app exits.

<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">
For instance, the the user may open a DB, read data and then turn off the PDA. What happens to the open DB? The app was not cleanly shutdown. is the DB still open?
<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">

When a PalmOS PDA turns off, the current app is not exited. When the PDA powers back on, everything is exactly in same state as before. In the above case, the DB will not be closed, but it will if the user exits the app.

Joe

The PToolboxLib guy.
http://www.geocities.com/retro_01775/PToolboxLib.htm