Thread: Virtual memory is increasing a lot when i run my application in linux

  1. #1
    Registered User
    Join Date
    Sep 2012
    Location
    Mumbai
    Posts
    3

    Lightbulb Virtual memory is increasing a lot when i run my application in linux

    I am running my application
    when i run the **TOP** command it is showing too much virtual memory

    Code:
    Thu Oct  4 18:11:01 IST 2012
    PID       USER      PR  NI  VIRT   RES  SHR  S %CPU %MEM    TIME+  COMMAND
    31248 root        18   0  28.1g  73m  1772 S 12.8  7.3   14:53.12 ommandserver     
    
    ThreadCount
        4
    VIRT--->virtual memory 28.1 GB it is very big
    how can i free that memory???
    If the application runs much more time will it lead to "Out of Memory Exception?"

    help me
    Last edited by Salem; 10-04-2012 at 07:16 AM. Reason: added a bit of formatting

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The answer, if any, will be specific to your code.

    Generally, a memory leak (which is a common cause of symptoms like memory usage increasing continually) is caused by code that dynamically allocates memory but does not release it. Every usage of operator new, in C++, must be matched by a corresponding operator delete, when the memory (or objects) are no longer required. There is no native garbage collection mechanism that will clean things up if you forget (unless you have specifically used such a mechanism but, given your question, you probably haven't done that). You will need to analyse your own code to work out where deallocation needs to occur (and ensure memory is only deallocated once).

    Eventually, if a program leaks enough memory (allocates memory but does not deallocate), it may run out of memory. In some (thankfully rare) worst cases, your program may starve *other* processes, or even the operating system itself, of necessary memory. What happens then depends on the operating system - the result can be "out of memory" indications, your program being terminated without explanation, your operating system hanging, or a whole slew of other possibilities.

    If the memory usage of your program is stable (i.e. doesn't keep increasing as the program is run longer) it could just mean your program requires a large amount of memory. A program that realistically needs 28GB is not all that common though.
    Last edited by grumpy; 10-04-2012 at 07:20 AM.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Sep 2012
    Location
    Mumbai
    Posts
    3

    Virtual memory is increasing to a great extent

    there is memory leak check in my application
    and there is no memory leak, we are printing in the logs for every transaction
    we have deleted every object with delete , and freed the buffers using free()

    my Doubt is about virtual memory
    what will happen, if virtual memory keep on increasing?
    and how to release it?
    difference between memory and virtual memory?




    Quote Originally Posted by grumpy View Post
    The answer, if any, will be specific to your code.

    Generally, a memory leak (which is a common cause of symptoms like memory usage increasing continually) is caused by code that dynamically allocates memory but does not release it. Every usage of operator new, in C++, must be matched by a corresponding operator delete, when the memory (or objects) are no longer required. There is no native garbage collection mechanism that will clean things up if you forget (unless you have specifically used such a mechanism but, given your question, you probably haven't done that). You will need to analyse your own code to work out where deallocation needs to occur (and ensure memory is only deallocated once).

    Eventually, if a program leaks enough memory (allocates memory but does not deallocate), it may run out of memory. In some (thankfully rare) worst cases, your program may starve *other* processes, or even the operating system itself, of necessary memory. What happens then depends on the operating system - the result can be "out of memory" indications, your program being terminated without explanation, your operating system hanging, or a whole slew of other possibilities.

    If the memory usage of your program is stable (i.e. doesn't keep increasing as the program is run longer) it could just mean your program requires a large amount of memory. A program that realistically needs 28GB is not all that common though.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > there is memory leak check in my application
    Please explain this.

    Some memory leak detection tools do not actually free memory to the point that it can be re-used.
    This is done so that they can also detect "use after free" errors in the program as well.

    The side-effect of this is that the program will use very large amounts of memory.

    If you're confident that there are no memory leaks, then you really should run the code without leak checking.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by maheshparimi View Post
    my Doubt is about virtual memory
    what will happen, if virtual memory keep on increasing?
    and how to release it?
    difference between memory and virtual memory?
    As Salem said, build without the memory leak checks. There is a good chance that the memory leak checker is causing the effect you're observing. The intent of such tools is usually that they will be used only during debugging, not executed in the final/released version of your program.

    Memory refers to any physical devices used to store data temporarily or permanently on your computer. In terms of the memory usage of your program, this typically refers to random access memory (RAM), which is faster than other devices, but also typically has less capacity than other devices. Virtual memory refers to use of another physical device (eg a hard drive) to emulate additional RAM, using all or part of the storage on that additional device (eg a swap file which takes part of the total storage available on a hard drive). The effect is to increase the amount of total memory the system can allocate to programs, with a performance trade-off in that speed of accessing data in virtual memory is significantly (often orders of magnitude) slower than RAM.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 09-15-2011, 03:28 PM
  2. Increasing memory allocation in function
    By Ramses800 in forum C Programming
    Replies: 3
    Last Post: 12-16-2008, 05:30 AM
  3. Replies: 2
    Last Post: 09-28-2006, 01:06 PM
  4. Increasing working memory in win XP
    By AngKar in forum C Programming
    Replies: 4
    Last Post: 04-24-2006, 06:01 PM
  5. Replies: 4
    Last Post: 03-29-2004, 07:56 PM

Tags for this Thread