12-02-2009 04:26 AM
I'm confused about what you are talking about.
Of course, memory fragmentation has nothing to do with memory leakage. They are two different phenomena. I thought someone had asked why memory seems to grow slightly from time to time and then go down again when you do some resets. These are most commonly caused by memory fragmentation. Memory leakage is a bug in the program. Memory fragmentation isn't.
I'm not sure if you were the person who asked that question and maybe you were talking about your program which has a memory leak. Memory leaks will eat up all memory usually pretty quickly.
In embedded systems, is usually best to declare an array of the structures or classes you want to use at the start of the program so that they'll be erased at the end of the program by the garbage collector. However, there are situations where you have to use dynamic allocation and then you must be careful to always free memory that you allocated or you'll create a leak. I generally try to avoid dynamic allocation in embedded code wherever possible (I'd consider a blackberry app as an embedded app). It's been too long since I used the persistant storage so I can't remember the API, so I can't remember if it forces you to allocate or what..... Usually persistent code is something that you plan on keeping around to hold some data associated with your app even when not running it for the next time you run (like an address book or something).
It all depends on your app.
12-02-2009 07:01 AM
I was the one who asked about the why the memory seemed to "grow."
12-02-2009 03:42 PM
That sounds odd but I understand from the previous posts why that happens. It makes me wonder why they don't compact the memory so those spaces so free memory doesn't decrease.