Need help with a memory leak

I am debugging an application on an embedded PPC design. For devolopment of the application and the debugging I am using the QNX
Momentics IDE. My problem is that when I start and stop my application several times that I debugging then my application detects there there is not enough free memory. Every time my app allocates the total free memory on my system minus 100kB. But after several start/stops my app detects at start that there is not enough free memory to start and I generate en error. I assume that when I “Terminate/Remove” my app that QNX Neutrino releases all the memory it had used, but that seens not to be the case. Has anybody a hint what could cause this effect.

Best regards
Theo Coppers

What you are seeing is probably the effect of memory fragmentation. Although there could be 200Meg of memory free it doesn’t mean you can allocated it in one block. In most cases virtual memory will take care of that problem, in theory it should work, however in practice its not perfect.

Depending how you detect the amount of free ram and the status of the program heap, allocating say 1M could actually end up sending the OS a request of a tad more then 1M.

Asking for all the memory minus 100ks is kind of dangerous, because while you are debugging the application, qconn or any other application already running in the system might run out ram.

Mario is right about this, but let me add, there are two ways I can think of that a process could remove memory from the system.

  1. Allocating permanent shared memory
  2. Accessing a resource manager that either intentionally does not give memory back (for example loading a disk driver) or itself has a memory leak.

Mario and Maschoen thanks for your explanations, I think I understand what happens. This means I have to restart my system from time to time to avoid this problem.

Best regards
Theo Coppers

It shouldn’t mean that at all. Both of the conditions I described are programatic oversites or bugs.