-   Programming (
-   -   Free Memory Not Reclaimed By System (

Sheado 09-27-2007 11:41 PM

Free Memory Not Reclaimed By System
Hi All,

I'm writing a media player application. I have no memory leaks as far as I can tell, but memory usage keeps increasing.

Basically, I read some data from a media file, put it a "new" array, and store it in a queue. In a separate thread i read the data array from this queue, decode, render, and then "delete" it.

So what exactly is is going on?? Why is memory usage increasing? I've read that linux will only reclaim free memory from the heap only if it is on the top of the heap (I verified this with a simple program) or until the program exits. But despite that, shouldn't my newly allocated data (happening during enqueueing) fit in the available yet deallocated (from my dequeue, decode, render, delete) heap space??

Why isn't my freed heap space being reused? Instead, the OS just keeps giving me more and more memory for every "new" I invoke.

I've been stuck on this for a week!! can somebody please help? Are there any compiler options that could help me? Should I just give up and do all my work on the stack??

Thanks!!! from a tired and sleepy developer,
really any suggestions would help =)

winfinit 09-28-2007 02:58 PM

when you are saying delete it, do you mean it is deliting acualt file or array? what is happeninig when you are trying to set your array to UNDEF after you are done with it?

i had similar issue with ftp application, what you could do is to write something that cleares your memory cache after it is clearing array junk.

here is a thread about memory clearing

here is a thread about memory clearing

jim mcnamara 09-28-2007 03:13 PM

Quick question - you have validated that there are no memory leaks using valgrind - electric fence?

Sheado 09-28-2007 03:38 PM

hi guys,
thanks for the quick response...

hi winfinit,

in one thread i'm creating my data arrays as follows:

unsigned char* data = new unsigned char[size];
and then putting them in a queue.

in another thread, i'm dequeuing then delete'ing the arrays as follows:

delete[] data;
As for freeing cache and memory through system calls, i would rather avoid that. I need my application to be cross-platform. Besides, when did memory reclamation - post deletion - become the application's responsibility?

hi jim mcnamara,

unfortunately i've been having a hard time running profilers because the front end of my application is Java (via JNI). Instead I've run my application 2 threads at a time and manually monitored /cat/{proc id}/status for memory issues. I know this is no guarantee, but i've been staring at this for a week and have yet to find an actual memory leak.

One thing I am starting to wonder is if this is related to multithreading. I'm using SDL to spawn the new threads which supposedly run in their own context yet still have access to data outside of it. Since i'm enqueuing in one thread and deleting in another, could that be the source of my problem??


All times are GMT -5. The time now is 09:36 AM.