I have a GNU g++
(v2.95.3) based program on Solaris 10
where we run out of heap condition (ENOMEM
) when malloc
or new
call fails to allocate further memory. As an ongoing situation, to better manage memory, I am looking for some solution technique where I would know the threshold limit in advance. For example, what is my max heap size and what is the current used up space in heap? Then will have some heuristic to determine that we are running low on heap and start de-allocating few burdens of memory to become light weight again, Looking for advises.
Asked
Active
Viewed 73 times
1

Dr. Debasish Jana
- 6,980
- 4
- 30
- 69
-
Sure there is no memory? Or is the memory just fragmented? Determining the current heap is likely no help, as that depends on other processes/threads, etc. – too honest for this site Sep 07 '15 at 13:13
-
Please pick a language. C is not C++. – too honest for this site Sep 07 '15 at 13:13
-
It might be more worthwhile to monitor how much memory you are using as by the time you get insufficient memory you're likely (at least on a 64 bit process) to have exhausted physical ram and started swapping bits of your data / code out to disk. – Tom Tanner Sep 07 '15 at 13:15
-
@Olaf this is a legacy code with some part in C++ and some in C. Problem is that whatever memory allocations done by the applications can be taken care of, but there are some more allocations due to Oracle DB calls through Pro*C for bulk insert and update mechanisms, that also need to be freed whenever required – Dr. Debasish Jana Sep 07 '15 at 15:46
-
@TomTanner I need a point to know we are crossing the threshold to start releasing memory, will brk / sbrk help? – Dr. Debasish Jana Sep 07 '15 at 15:47
-
Is this post of any help here? http://stackoverflow.com/questions/6988487/what-does-brk-system-call-do – Dr. Debasish Jana Sep 07 '15 at 16:28
-
Why are you asking almost the same question you already posted one week ago here: http://stackoverflow.com/questions/32338546/better-memory-heap-management-on-solaris-10 ? I already suggested a solution there. Did you try it? Why aren't you answering to the questions asking you to check your actual memory usage? Is your process 32 bit or 64 bit? How much RAM is there on your machine? What is the size of the swap area? What are reporting `vmstat` and `swap -s` when the issue is about to happen? What makes you feel you are hitting a heap threshold? – jlliagre Sep 07 '15 at 23:41
-
@jlliagre Appreciate your comments and suggestions. Will answer to these. My application is a long running data processing application where very large scale data gets processed and get flushed into DB suitably. In the process, at some point of time, I get ENOMEM where malloc fails to allocate any further. Thereafter, I may relinquish some memory to recover. However, I was looking for a preventive one, when do I know I am on danger zone, so need to free some memory before actually falling in the danger zone where malloc starts failing. Rather than recovery I would prefer the preventive option. – Dr. Debasish Jana Sep 08 '15 at 02:55