The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem with memory leak kshk123 HP-UX 2 05-25-2009 07:01 AM
memory leak problem sonali High Level Programming 5 05-25-2009 06:55 AM
memory leak? lenna IP Networking 2 05-25-2009 06:35 AM
Memory leak in pthread mindTeaser UNIX for Advanced & Expert Users 4 05-18-2009 01:30 AM
cpu, memory and virtual memory usage ocelot UNIX for Dummies Questions & Answers 4 12-01-2008 07:57 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-17-2006
shriashishpatil shriashishpatil is offline
Registered User
  
 

Join Date: Dec 2005
Location: Pune
Posts: 81
about virtual memory and memory leak

Hi,

First of all I appreciate this group very much for its informative discussions and posts.

Here is my question.

I have one process whose virtual memory size increases linearly from 6MB to 12MB in 20 minutes. Does that mean my process has memory leaks?

In what cases does the memory leak?. I just have preliminary idea that if you donot free the memory which is not in use, u have memory leak in ur program.

It would be really great if someone can post info about memory leak. Some link would do.

Thanks in advance,

-Ashish
  #2 (permalink)  
Old 02-17-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Quote:
It would be really great if someone can post info about memory leak. Some link would do.
could be due to the allocation logic added in the code to reclaim discarded memory

have signal handlers as guards in your program,
whenever the program crashes due to illegal access
somehow you need to free the memory acquired through malloc

dangling pointers is one such case
just assign NULL to freed members

programs resisting to release the memory (heap) eventually increases the heap size
  #3 (permalink)  
Old 02-17-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
The system calls brk() or sbrk() on behalf of the process to get chunks of memory.
As the program runs and requests more memory, the system calls for more.

Generally, this memory accumulates, with the idea that since the processes needed it before, it may well need it again. Calling brk() & sbrk() is expensive.

The simple way to see a memory leak is have the code run for longer periods. If memory continually grows, then there is probably problem.

If you need to find the leak - try either Electric Fence or Valgrind.
They are available free, and have been ported to most versions of UNIX.
  #4 (permalink)  
Old 02-20-2006
izy100 izy100 is offline
Registered User
  
 

Join Date: Nov 2002
Location: Singapore
Posts: 128
I have a C program that I suspect of memory leak.
However, the memory leak occurs when I kill -9 the program and restart the program to run as a daemon.
I didn't see the memory leak problem when the daemon is not killed and restarted at least 5 times.

The CPU usage on the server drop to ZERO everytime I kill the process BUT whenever I restart the process, it consume 2% more than it did the previous time.

Is this possible? I dun understand why did the CPU util dropped to ZERO after I kill the porcess if it is a memory leak.
  #5 (permalink)  
Old 02-20-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
Why not create a SIGTERM signal handler that does a graceful exit? Graceful meaning you call an atexit() handler to clean up memory.

kill -9 is generally a bad idea. Even if you don't write an exit handler, do not use
SIGKILL (kill -9) because it can prevent any further operations by the system on behalf of the process. The process leaves junk behind when this happens.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:03 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0