Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-27-2007, 11:41 PM   #1
LQ Newbie
Registered: Sep 2004
Posts: 4

Rep: Reputation: 0
Unhappy 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 =)
Old 09-28-2007, 02:58 PM   #2
Registered: Jul 2006
Location: FL, Delray Beach
Distribution: Slackware11, LFS
Posts: 67

Rep: Reputation: 15
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
Old 09-28-2007, 03:13 PM   #3
jim mcnamara
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Quick question - you have validated that there are no memory leaks using valgrind - electric fence?
Old 09-28-2007, 03:38 PM   #4
LQ Newbie
Registered: Sep 2004
Posts: 4

Original Poster
Rep: Reputation: 0
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??



leak, memory, system

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
installed system memory differs from mounted (available) memory landroni Debian 5 08-13-2007 06:43 AM
How to free up memory? arindom Linux - Newbie 4 12-29-2006 03:49 AM
Does free( ) immediatly free the memory? Rayven Programming 24 11-06-2006 02:24 AM
system ram never being reclaimed?? infamous41md Linux - Newbie 5 05-20-2004 10:43 PM
Windows reclaimed daul booted drive tkofkc Linux - Newbie 4 12-05-2002 12:58 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:43 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration