Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory leak in c++

I am running my c++ application on an intel Xscale device. The problem is, when I run my application offtarget (Ubuntu) with Valgrind, it does not show any memory leaks.

But when I run it on the target system, it starts with 50K free memory, and reduces to 2K overnight. How to catch this kind of leakage, which is not being shown by Valgrind?

like image 698
Ajay Avatar asked Apr 20 '09 08:04

Ajay


2 Answers

A common culprit with these small embedded deviecs is memory fragmentation. You might have free memory in your application between 2 objects. A common solution to this is the use of a dedicated allocator (operator new in C++) for the most common classes. Memory pools used purely for objects of size N don't fragment - the space between two objects will always be a multiple of N.

like image 143
MSalters Avatar answered Oct 07 '22 07:10

MSalters


It might not be an actual memory leak, but maybe a situation of increasing memory usage. For example it could be allocating a continually increasing string:

string s;
for (i=0; i<n; i++)
  s += "a";

50k isn't that much, maybe you should go over your source by hand and see what might be causing the issue.

like image 40
1800 INFORMATION Avatar answered Oct 07 '22 07:10

1800 INFORMATION