about virtual memory and memory leak


 
Thread Tools Search this Thread
Top Forums Programming about virtual memory and memory leak
# 1  
Old 02-17-2006
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  
Old 02-17-2006
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  
Old 02-17-2006
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  
Old 02-20-2006
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  
Old 02-20-2006
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Web Development

Finding Cause of Memory Leak

Hi We have just got a dedicated server with Fasthosts, O/S is Linux CentOS 6 64 bit. It was a fresh install and I have just moved one WordPress site onto there. The problem is we seem to be getting a memory leak (that's what Fasthosts said) and the database (I think) keeps crashing, so we... (3 Replies)
Discussion started by: Pokeyzx
3 Replies

2. Programming

Help regarding memory leak in this C program

I have written this code in C which reads a very large collection of text files and does some processing. The problem with this code is that there are memory leaks which I am not able to figure out as to where the problem is. When I run this code, and see the memory usage using top command, then I... (7 Replies)
Discussion started by: shoaibjameel123
7 Replies

3. Red Hat

Memory leak

Hi all I am using RED HAT 5.4, and i am getting memory uses problem. when i use "sync;echo 3 > /proc/sys/vm/drop_cache" command the memory will release after 2,3 hour memory show 95%. pls suggest right way. thanks (37 Replies)
Discussion started by: reply.ravi
37 Replies

4. Programming

Memory Leak

Hi, I am trying a database server which keeps a B+ plus tree structure and works on it. I am trying to find the memory used/leak while executing this process. I check the memory leak by using ps uax command. When i execute a delete query i am sure that my code frees up the existing... (9 Replies)
Discussion started by: kumaran_5555
9 Replies

5. IP Networking

memory leak?

Hi All, my client server application can work in two modes: 1) one direction - only client sends msgs to server 2) two directions - server gives 'answers' to client. when program run in the first mode it looks OK, but when server answers to client than client's application exit its... (2 Replies)
Discussion started by: lenna
2 Replies

6. UNIX for Advanced & Expert Users

Memory leak in pthread

helo frnds, I am using RHEL5 and C lang for development. I am getting some memory leak problem in pthread. I hav developed a program which creates two threads for listening purpose on two diff ports. both the child threads are doing same job but on diff port no. I am using... (4 Replies)
Discussion started by: mindTeaser
4 Replies

7. Programming

Memory LEAK with pthreads

I have this code... #include <stdio.h> #include <iostream> #include <pthread.h> static void* cliente(void *datos); int main() { pthread_attr_t tattr; int ret; size_t size = PTHREAD_STACK_MIN + 0x0100; ret = pthread_attr_init(&tattr); ret =... (8 Replies)
Discussion started by: JEscola
8 Replies

8. UNIX for Dummies Questions & Answers

cpu, memory and virtual memory usage

Hi All, Does anyone know what the best commands in the UNIX command line are for obtaining this info: current CPU usage memory usage virtual memory usage preferably with date and time parameters too? thanks ocelot (4 Replies)
Discussion started by: ocelot
4 Replies

9. AIX

ulimits max locked memory virtual memory

Hi, Would any one be so kind to explain me : are ulimits defined for each user seperately ? When ? Specialy what is the impact of : max locked memory and virtual memory on performance of applications for a user. Many thanks. PS : this is what I can see in MAN : ulimit ] ... (5 Replies)
Discussion started by: big123456
5 Replies
Login or Register to Ask a Question