Memory alloc problem while exiting | developer.brewmp.com Memory alloc problem while exiting | developer.brewmp.com

Developer

Memory alloc problem while exiting

Forums:

Hi,
I am facing a problem. I have 2 applets where 2nd app stops the other one while starting up (of the app) and the 2nd applet while exiting calls again the first one. Now I have some global variables( allocated and stored in heap) stored in case of first app before it stops with some values.
But when the 1st app is called during the second time the global variables doesnot have the right values inside. The values are getting corrupted/deleted.
My doubt is/are
Quote:1. Is there any thing that Brew is taking care to Free unreleased memories if we dont free in the applet after we end the applet? If this is the case is there any way that I can make my app or the memory allocated to be not affected when I come back to the 1st app the second time ( Like setting some flags while allocating etc).
2. I have seen MALLOC (AEEMALLOC) and IHeap. Both does almost same as far as my understanding from the docs. Is there any difference between the two?

Please give me your valuable suggestions
Thanks in Advanve
Jacob

There is no garbage collection in the BREW environment, as in Java. Everything you allocate, you must manually deallocate when the application closes.
Similarly, when you close an application, it must be entirely deallocated. If you want to store values for retrieval later, you will need to write them to the file system and read them back when you launch again.
Hope that helps,

There is no garbage collection in the BREW environment, as in Java. Everything you allocate, you must manually deallocate when the application closes.
Similarly, when you close an application, it must be entirely deallocated. If you want to store values for retrieval later, you will need to write them to the file system and read them back when you launch again.
Hope that helps,

Thanks
But if Brew doesnt clean it up the global variable values that is not freed should have the right values. But in my case these values are getting corrupted.
Quote:Does it mean that while closing the app the not-freed global variables will be flushed or reinitialized by Brew? If yes is there a way to avoid it?

Thanks
But if Brew doesnt clean it up the global variable values that is not freed should have the right values. But in my case these values are getting corrupted.
Quote:Does it mean that while closing the app the not-freed global variables will be flushed or reinitialized by Brew? If yes is there a way to avoid it?

When your app is destroyed, memory is reclaimed. Thus the corruption... There is no telling what will be in that memory location when you create another application module.
Global variables are ONLY global to your application, NOT the environment. If you destroy the app, your variables are gone because you no longer control that memory.
Hope that helps

When your app is destroyed, memory is reclaimed. Thus the corruption... There is no telling what will be in that memory location when you create another application module.
Global variables are ONLY global to your application, NOT the environment. If you destroy the app, your variables are gone because you no longer control that memory.
Hope that helps

Thanks Zerocool,
One more question
Is there a way to make Brew avoid the reclaim of a particular global location?. That is I made a variable globally and allocated memory in the app. The value inside the variable should persist when the app is revisited (probably immediately after closing the app)
Thanks
Jacob

Thanks Zerocool,
One more question
Is there a way to make Brew avoid the reclaim of a particular global location?. That is I made a variable globally and allocated memory in the app. The value inside the variable should persist when the app is revisited (probably immediately after closing the app)
Thanks
Jacob

Abraham Jacob M wrote:Thanks ,
One more question
Is there a way to make Brew avoid the reclaim of a particular global location?. That is I made a variable globally and allocated memory in the app. The value inside the variable should persist when the app is revisited (probably immediately after closing the app)
Keep the global variable inside the app structure, so that you have control over the lifetime of that variable.
As Zerocool said, db or file can be used to persist the value of variable.

Abraham Jacob M wrote:Thanks ,
One more question
Is there a way to make Brew avoid the reclaim of a particular global location?. That is I made a variable globally and allocated memory in the app. The value inside the variable should persist when the app is revisited (probably immediately after closing the app)
Keep the global variable inside the app structure, so that you have control over the lifetime of that variable.
As Zerocool said, db or file can be used to persist the value of variable.

Yep i got it ...
Thanks
One more question ... Will the heap be lost or reclaimed for further use ( may be by Brew)if I dont free my(global variable assigned memory thru MALLOC) memory in use if I close my Applet?

Yep i got it ...
Thanks
One more question ... Will the heap be lost or reclaimed for further use ( may be by Brew)if I dont free my(global variable assigned memory thru MALLOC) memory in use if I close my Applet?

You can use ISHELL_SetPrefs/ISHELL_GetPrefs for small, temp storage you wish to persist accros applet launches/exits.

You can use ISHELL_SetPrefs/ISHELL_GetPrefs for small, temp storage you wish to persist accros applet launches/exits.

Abraham Jacob M wrote:Yep i got it ...
Thanks
One more question ... Will the heap be lost or reclaimed for further use ( may be by Brew)if I dont free my(global variable assigned memory thru MALLOC) memory in use if I close my Applet?
Yes, as soon as you close your application BREW would do that, and you would get BPOINT type leak.

Abraham Jacob M wrote:Yep i got it ...
Thanks
One more question ... Will the heap be lost or reclaimed for further use ( may be by Brew)if I dont free my(global variable assigned memory thru MALLOC) memory in use if I close my Applet?
Yes, as soon as you close your application BREW would do that, and you would get BPOINT type leak.