473,722 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Memory Leak/Profiling

Hello,

I'm trying to track down a memory issue with a C++ application that
I'm working on:

In a nutshell, the resident memory usage of my program continues to
grow as the program runs. It starts off at a nice 4% of memory, then
slowly grows up to 50% and beyond. This translates to around 2 gigs
of physical memory, and that's really way more memory than this
program should be taking up.

I'm looking for a tool that can tell me where this memory is being
allocated to.

I've fiddled around with both purify and ccmalloc without much
success. I suspect that what I'm seeing here is not a memory leak in
the traditional sense -- by which I mean, memory that has been
allocated and no longer has any pointers pointing to it.

I have a suspicion that somewhere in my program, a vector is growing
out of control. From my understanding, this type of growth won't be
detected by programs like purify because purify is looking for "true"
memory leaks.

Essentially what I'm looking for is a memory profiler -- I want to be
able to look at the memory that has been allocated to my program and
see what that memory is.

Does anyone know of any tools that will do this? Thanks!

-Michael Jeung

May 19 '07 #1
9 4209
On May 19, 2:03 am, jeungs...@gmail .com wrote:
Hello,

I'm trying to track down a memory issue with a C++ application that
I'm working on:

In a nutshell, the resident memory usage of my program continues to
grow as the program runs. It starts off at a nice 4% of memory, then
slowly grows up to 50% and beyond. This translates to around 2 gigs
of physical memory, and that's really way more memory than this
program should be taking up.

I'm looking for a tool that can tell me where this memory is being
allocated to.

I've fiddled around with both purify and ccmalloc without much
success. I suspect that what I'm seeing here is not a memory leak in
the traditional sense -- by which I mean, memory that has been
allocated and no longer has any pointers pointing to it.

I have a suspicion that somewhere in my program, a vector is growing
out of control.
What you are describing looks like memory leak caused by
fragmentation of memory. This type of leak is probably not
caused by vector, but buy large number of alloc's/free's
of varying sizes. To solve this problem you have to actually
do same thing as vector. To preallocate pools for each alloc
size and in that way keep fragmentation at bay.
In order to solve this successfully, you have to find out
what sizes are allocated/freed most.
If you can't determine that, even pool allocator won't help
you, because it will just preallocate too much blocks
for different sizes.
Or, you can just restart application automatically
if memory usage reaches some predefined peak ;)
(once I did that, because controlling allocations was
impossible as this was rpc like server, and people might
do anything there )

Greetings, Branimir.

May 19 '07 #2
je*******@gmail .com wrote:
Hello,

I'm trying to track down a memory issue with a C++ application that
I'm working on:

In a nutshell, the resident memory usage of my program continues to
grow as the program runs. It starts off at a nice 4% of memory, then
slowly grows up to 50% and beyond. This translates to around 2 gigs
of physical memory, and that's really way more memory than this
program should be taking up.
Well depending on the operating system, that might be expected behavior
and what you are seeing is the natural result of memory being allocated
and freed. Freed memory may not be reclaimed by the operating system
until it is required elsewhere. This results in the illusion that your
program has a leek.

--
Ian Collins.
May 19 '07 #3
Ian Collins wrote:
je*******@gmail .com wrote:
>Hello,

I'm trying to track down a memory issue with a C++ application that
I'm working on:

In a nutshell, the resident memory usage of my program continues to
grow as the program runs. It starts off at a nice 4% of memory, then
slowly grows up to 50% and beyond. This translates to around 2 gigs
of physical memory, and that's really way more memory than this
program should be taking up.
Well depending on the operating system, that might be expected behavior
and what you are seeing is the natural result of memory being allocated
and freed. Freed memory may not be reclaimed by the operating system
until it is required elsewhere. This results in the illusion that your
program has a leek.
Whoops, not a vegetable, but a memory leak!

--
Ian Collins.
May 19 '07 #4

je*******@gmail .com wrote:
Hello,

I'm trying to track down a memory issue with a C++ application that
I'm working on:

In a nutshell, the resident memory usage of my program continues to
grow as the program runs. It starts off at a nice 4% of memory, then
slowly grows up to 50% and beyond. This translates to around 2 gigs
of physical memory, and that's really way more memory than this
program should be taking up.

I'm looking for a tool that can tell me where this memory is being
allocated to.

I've fiddled around with both purify and ccmalloc without much
success. I suspect that what I'm seeing here is not a memory leak in
the traditional sense -- by which I mean, memory that has been
allocated and no longer has any pointers pointing to it.

I have a suspicion that somewhere in my program, a vector is growing
out of control. From my understanding, this type of growth won't be
detected by programs like purify because purify is looking for "true"
memory leaks.

Essentially what I'm looking for is a memory profiler -- I want to be
able to look at the memory that has been allocated to my program and
see what that memory is.

Does anyone know of any tools that will do this? Thanks!

-Michael Jeung
It is deeply abnormal! And i suggest you trace out all the memory
usages in you application. Then you can see what type and size of
memories you allocated. I believe there might be some memory leaks you
have not detected!

May 19 '07 #5
On May 19, 3:01 am, Branimir Maksimovic <b...@hotmail.c omwrote:
On May 19, 2:03 am, jeungs...@gmail .com wrote:
I'm trying to track down a memory issue with a C++ application that
I'm working on:
In a nutshell, the resident memory usage of my program continues to
grow as the program runs. It starts off at a nice 4% of memory, then
slowly grows up to 50% and beyond. This translates to around 2 gigs
of physical memory, and that's really way more memory than this
program should be taking up.
I'm looking for a tool that can tell me where this memory is being
allocated to.
I've fiddled around with both purify and ccmalloc without much
success. I suspect that what I'm seeing here is not a memory leak in
the traditional sense -- by which I mean, memory that has been
allocated and no longer has any pointers pointing to it.
I have a suspicion that somewhere in my program, a vector is growing
out of control.
What you are describing looks like memory leak caused by
fragmentation of memory. This type of leak is probably not
caused by vector, but buy large number of alloc's/free's
of varying sizes.
Not necessarily. Modern collectors are pretty good at reducing
fragmentation.

The most frequent cause of memory leaks that I've seen in Java
(which has a moving collector, so doesn't suffer from
fragmentation at all) is simply objects which register for
events, and forget to deregister when they turn the source of
events off. So the event dispatching map just grows and grows.
Instrumenting the standard containers (using, say, the decorator
pattern) to keep track of the number of entries might help.
To solve this problem you have to actually
do same thing as vector. To preallocate pools for each alloc
size and in that way keep fragmentation at bay.
That's a strategy used by some mallocs. If he's having such a
problem, switching to a different malloc/free might help. (For
the most part, the system operator new will just call malloc.)
In order to solve this successfully, you have to find out
what sizes are allocated/freed most.
If you can't determine that, even pool allocator won't help
you, because it will just preallocate too much blocks
for different sizes.
A good implementation of malloc will detect this automatically,
and adjust its strategy accordingly.

--
James Kanze (Gabi Software) email: ja*********@gma il.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

May 19 '07 #6
On May 19, 10:35 am, James Kanze <james.ka...@gm ail.comwrote:
On May 19, 3:01 am, Branimir Maksimovic <b...@hotmail.c omwrote:
On May 19, 2:03 am, jeungs...@gmail .com wrote:
I'm trying to track down a memory issue with a C++ application that
I'm working on:
In a nutshell, the resident memory usage of my program continues to
grow as the program runs. It starts off at a nice 4% of memory, then
slowly grows up to 50% and beyond. This translates to around 2 gigs
of physical memory, and that's really way more memory than this
program should be taking up.
I'm looking for a tool that can tell me where this memory is being
allocated to.
I've fiddled around with both purify and ccmalloc without much
success. I suspect that what I'm seeing here is not a memory leak in
the traditional sense -- by which I mean, memory that has been
allocated and no longer has any pointers pointing to it.
I have a suspicion that somewhere in my program, a vector is growing
out of control.
What you are describing looks like memory leak caused by
fragmentation of memory. This type of leak is probably not
caused by vector, but buy large number of alloc's/free's
of varying sizes.

Not necessarily. Modern collectors are pretty good at reducing
fragmentation.
Yes, those are moving collectors that can't be implemented for C++
because of raw memory pointers and pointer arithmetic.
Altough one can imeplement such easilly with disciplined programing
and usage of objects as pointers instead of raw ones.
But, non moving collectors have same problem as manual
memory management.
To solve this problem you have to actually
do same thing as vector. To preallocate pools for each alloc
size and in that way keep fragmentation at bay.

That's a strategy used by some mallocs. If he's having such a
problem, switching to a different malloc/free might help. (For
the most part, the system operator new will just call malloc.)
I have tried to replace malloc in different ways
with my implementation on linux (because of same problem), but
unsucessfully. LD_PRELOAD won;t work because libc functions
call malloc during init time (so nobody knows which private function
of malloc interface will be called), and also malloc hooks can;t be
used because malloc uses those for it's internal purposes,
even that linux docs say opposite.
Problem is that when programers play smart and don;t use
global operator new or some function that wraps calls to malloc, then
since C don;t have interface for replacing that function
this is sometimes not an option.
>
In order to solve this successfully, you have to find out
what sizes are allocated/freed most.
If you can't determine that, even pool allocator won't help
you, because it will just preallocate too much blocks
for different sizes.

A good implementation of malloc will detect this automatically,
and adjust its strategy accordingly.
I never saw such malloc. I can imagine that allocs would be
very costly with such implementation.
But my colleague and I have solved problem by aligning
allocation for different sizes into predefined sizes.
This uses more memory but does not have fragmentation that
much. This wasn't satisfactory solution for applications
that hold lot of memory since memory usage was a bit high.
So I really can't imagine general purpose allocator that
can solve all problems. In practice application programmer
always have to think about allocation/deallocation strategy,
if writing apps that will allocate/free
non-stop and run for a long time.

Greetings, Branimir.

May 19 '07 #7
On May 19, 1:06 pm, Branimir Maksimovic <b...@hotmail.c omwrote:
On May 19, 10:35 am, James Kanze <james.ka...@gm ail.comwrote:
On May 19, 3:01 am, Branimir Maksimovic <b...@hotmail.c omwrote:
On May 19, 2:03 am, jeungs...@gmail .com wrote:
I'm trying to track down a memory issue with a C++ application that
I'm working on:
In a nutshell, the resident memory usage of my program continues to
grow as the program runs. It starts off at a nice 4% of memory, then
slowly grows up to 50% and beyond. This translates to around 2 gigs
of physical memory, and that's really way more memory than this
program should be taking up.
I'm looking for a tool that can tell me where this memory is being
allocated to.
I've fiddled around with both purify and ccmalloc without much
success. I suspect that what I'm seeing here is not a memory leak in
the traditional sense -- by which I mean, memory that has been
allocated and no longer has any pointers pointing to it.
I have a suspicion that somewhere in my program, a vector is growing
out of control.
What you are describing looks like memory leak caused by
fragmentation of memory. This type of leak is probably not
caused by vector, but buy large number of alloc's/free's
of varying sizes.
Not necessarily. Modern collectors are pretty good at reducing
fragmentation.
Yes, those are moving collectors that can't be implemented for C++
because of raw memory pointers and pointer arithmetic.
Altough one can imeplement such easilly with disciplined programing
and usage of objects as pointers instead of raw ones.
But, non moving collectors have same problem as manual
memory management.
Not necessarily.
To solve this problem you have to actually
do same thing as vector. To preallocate pools for each alloc
size and in that way keep fragmentation at bay.
That's a strategy used by some mallocs. If he's having such a
problem, switching to a different malloc/free might help. (For
the most part, the system operator new will just call malloc.)
I have tried to replace malloc in different ways
with my implementation on linux (because of same problem), but
unsucessfully.
I've never had any problem on Solaris. If the default malloc
has caused problems, switching to one of the others delivered
with the system generally solved them.

It's important to realize, too, that while fragmentation will
generally increase the memory footprint of the program, it
almost never causes real leaking; the footprint may be larger,
but it is stable.
LD_PRELOAD won;t work because libc functions
call malloc during init time (so nobody knows which private function
of malloc interface will be called), and also malloc hooks can;t be
used because malloc uses those for it's internal purposes,
even that linux docs say opposite.
Problem is that when programers play smart and don;t use
global operator new or some function that wraps calls to malloc, then
since C don;t have interface for replacing that function
this is sometimes not an option.
Which malloc/free you use is decided at link time. So there's
no problem with static initializers (unless the malloc/free
requires some special initialization) .
In order to solve this successfully, you have to find out
what sizes are allocated/freed most.
If you can't determine that, even pool allocator won't help
you, because it will just preallocate too much blocks
for different sizes.
A good implementation of malloc will detect this automatically,
and adjust its strategy accordingly.
I never saw such malloc. I can imagine that allocs would be
very costly with such implementation.
Not really. All it entails is maintaining a bit of statistical
data. But it's true that it is generally easier for the vendor
to provide several different mallocs, and let the user
explicitly choose at link time.
But my colleague and I have solved problem by aligning
allocation for different sizes into predefined sizes.
This uses more memory but does not have fragmentation that
much. This wasn't satisfactory solution for applications
that hold lot of memory since memory usage was a bit high.
So I really can't imagine general purpose allocator that
can solve all problems. In practice application programmer
always have to think about allocation/deallocation strategy,
if writing apps that will allocate/free
non-stop and run for a long time.
That hasn't been my experience. Of course, very few of my
applications run for more than about ten years; maybe that's not
long enough.

--
James Kanze (Gabi Software) email: ja*********@gma il.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

May 19 '07 #8
On May 19, 8:52 pm, James Kanze <james.ka...@gm ail.comwrote:
On May 19, 1:06 pm, Branimir Maksimovic <b...@hotmail.c omwrote:


It's important to realize, too, that while fragmentation will
generally increase the memory footprint of the program, it
almost never causes real leaking; the footprint may be larger,
but it is stable.
I performed bit of search, and this is first what I have found.
http://www.codeproject.com/cpp/MemLe...gmentation.asp,
though I don;t see why not code in article just implements
operator new in class.
Seems that I'll get same headaches on windows as on linux ;)
.. In practice application programmer
always have to think about allocation/deallocation strategy,
if writing apps that will allocate/free
non-stop and run for a long time.

That hasn't been my experience. Of course, very few of my
applications run for more than about ten years; maybe that's not
long enough.
Well, I've over generalized it. I said that based on
my experience with linux, but I guess there can be
apps that never overload either class or global new
and have not problems, even when doing large number
of allocations.

Greetings, Branimir.

May 19 '07 #9
On May 18, 8:03 pm, jeungs...@gmail .com wrote:
Hello,

I'm trying to track down a memory issue with a C++ application that
I'm working on:

In a nutshell, the resident memory usage of my program continues to
grow as the program runs. It starts off at a nice 4% of memory, then
slowly grows up to 50% and beyond. This translates to around 2 gigs
of physical memory, and that's really way more memory than this
program should be taking up.

I'm looking for a tool that can tell me where this memory is being
allocated to.

I've fiddled around with both purify and ccmalloc without much
success. I suspect that what I'm seeing here is not a memory leak in
the traditional sense -- by which I mean, memory that has been
allocated and no longer has any pointers pointing to it.

I have a suspicion that somewhere in my program, a vector is growing
out of control. From my understanding, this type of growth won't be
detected by programs like purify because purify is looking for "true"
memory leaks.

Essentially what I'm looking for is a memory profiler -- I want to be
able to look at the memory that has been allocated to my program and
see what that memory is.

Does anyone know of any tools that will do this? Thanks!

-Michael Jeung
Have you looked into Valgrind? It sometimes works in problems where
Purify will fail.

--
EventStudio 4.0 - http://www.EventHelix.com/EventStudio
Sequence Diagram based System Modeling Tool

May 20 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2934
by: barkha shah | last post by:
Hi , Can any one please suggest me the memory Leak detecting tool in Visual Studio.Net 2003 Release version Framework. Can I use Numega Bounds checker for this. Thanks and Regards. barkha
5
2636
by: iceColdFire | last post by:
Hi, I am writing some hybrid application s using C/C++ modules together....Here I have created and used a lot of malloc(...) and new(...) operators. I am interested in checking on the optimisation part of the programs...like memory consumed,memory leak , processor utilisation and like...most of the info I got from task manager...however still I cand find way to check on memory leaks...
6
461
by: Mike | last post by:
..NET 1.1 Hi. My C# .NET application has a memory leak - if I leave it running for hours then the system ends up using 500MB+ of virtual memory, which is released immediately when I close the app. Now, I thought this would be impossible with automatic garbage collection, but it seems this is not the case. The application is threaded and all work is done within spawned threads. No
15
1768
by: yehoshua | last post by:
Is there anyway to explicitly tell the garbage collector you are done with an object? In my app I have a point where I am sure there should be no references to an set of objects (well i remove what i assume is the last reference to them) and I want them to be GCed. But for some reason my app is leaking memory and that is the only place I can think of that something could be going wrong. I want to just say...
13
1518
by: Nikolay Petrov | last post by:
I've got this issue: When I start my application it takes a lot of memory. I guess this is caused by CLR. That's fine. But every time the app performs an action (open new form, load data in dataset, something, it doesn't matter) the memory used by the application increases. After using it half an hour it grows so big that most of PCs here act very slowly. Is this behavior caused somehow by my lack of programming knowledge or something...
14
1781
by: Don HO | last post by:
Hi, We have found a memory leak on a php server after executing a php/mysql application. The configuration is php 4.3.1 + mysql on windows server 2000 with IIS. Does the memory leak come from the php application itself (ie. a bug on the php developed scripts)? If not, where could be the problem?
30
4696
by: MAG1301 | last post by:
I've detected memory leaks in our huge .NET 1.1 C# application but couldn't localize them directly. So I've reduced the code to the following console application: using System; using System.IO; namespace MemLeak { class MemLeak
0
1254
by: bob | last post by:
Hi, VS2005 Windows App. Datalayer talking to a local SQL Anywhere 9 Database using OleDb. App runs OK for about a week then crashes in the Datalayer. The crash occurs attempting to retrieve data via a SPROC. The reported error is 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt..' Also sometimes get: 'No error message available, result code: E_UNEXPECTED(0x8000FFFF)..'
9
4176
by: deerchao | last post by:
I'm developing a WinForms application. It slowly eats up memory, one client reported that it took 200MB or more, and finnaly crashed. I myself noticed it's common to use up 30MB memory, but if I minimize it (all the Forms will Hide, only a NotifyIcon is shown at the System Notification Area), the memory usage comes down to 8MB immediately. After that, even if I show the Forms again, it uses only 8MB memory. Do I have another way to...
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.