i'm recycling large bitmap files for my game in hopes of avoiding out of memory errors. however the system does not appear to be making the memory available for new bitmap allocation no matter how many bitmaps I recycle. it always appears to crash at the same time as if I didn't recycle anything. I'm using system.gc to force garbage collection after every recycle command, but it doesn't seem to make a difference. neither does view.getResources().flushLayoutCache(); or view.destroyDrawingCache();.
here is the log before the crash:
02-12 16:24:45.006: D/dalvikvm(1627): GC_EXPLICIT freed 3113K, 20% free 25450K/31751K, paused 77ms+47ms
02-12 16:24:45.006: D/MainGamePanel(1627): system.gc called
02-12 16:24:46.966: D/dalvikvm(1627): GC_CONCURRENT freed <1K, 14% free 27403K/31751K, paused 35ms+140ms
02-12 16:24:52.975: D/dalvikvm(1627): GC_CONCURRENT freed 2546K, 16% free 26871K/31751K, paused 60ms+91ms
02-12 16:25:35.253: D/dalvikvm(1627): GC_CONCURRENT freed 1742K, 15% free 27138K/31751K, paused 51ms+44ms
02-12 16:26:38.351: D/dalvikvm(1627): GC_CONCURRENT freed 1923K, 15% free 27226K/31751K, paused 87ms+69ms
02-12 16:28:03.941: D/dalvikvm(1627): GC_CONCURRENT freed 3577K, 20% free 25696K/31751K, paused 26ms+57ms
02-12 16:28:08.879: D/Datapool(1627): recycle called
02-12 16:28:10.356: D/dalvikvm(1627): GC_EXPLICIT freed 934K, 20% free 25578K/31751K, paused 73ms+73ms
02-12 16:28:10.356: D/Datapool(1627): system.gc called
02-12 16:28:12.356: D/dalvikvm(1627): GC_EXPLICIT freed 732K, 22% free 24845K/31751K, paused 60ms+66ms
02-12 16:28:12.356: D/Datapool(1627): system.gc called
02-12 16:28:13.536: D/dalvikvm(1627): GC_FOR_ALLOC freed 85K, 23% free 24760K/31751K, paused 1128ms
02-12 16:28:13.756: I/dalvikvm-heap(1627): Grow heap (frag case) to 26.915MB for 2797584-byte allocation
02-12 16:28:15.486: D/dalvikvm(1627): GC_CONCURRENT freed 0K, 14% free 27492K/31751K, paused 79ms+114ms
02-12 16:28:17.428: D/dalvikvm(1627): GC_FOR_ALLOC freed 0K, 14% free 27492K/31751K, paused 649ms
02-12 16:28:17.428: I/dalvikvm-heap(1627): Forcing collection of SoftReferences for 1243076-byte allocation
02-12 16:28:18.715: D/dalvikvm(1627): GC_BEFORE_OOM freed 0K, 14% free 27492K/31751K, paused 1276ms
02-12 16:28:18.715: E/dalvikvm-heap(1627): Out of memory on a 1243076-byte allocation.
If it was possible you could try to change the gc algorithm that the dalvikVM implements.
But I think this is not an option.
The dalvik implements the mark and sweep
I've seem some threads about problems with images.
One snippet called my attention:
try this as soon as the image is dereferenced:
bitmap.recycle();
System.gc();
Runtime.getRuntime().gc();
This thread is very complete about image management.
Strange out of memory issue while loading an image to a Bitmap object
Related
In my app, I load the interactive meeting URL on wkWebView, but I've noticed that the allocated memory has been gradually increasing.
When the app starts, memory is around 22 MB, but memory increases by the second.
How can I stop my memory from gradually increasing over time?
https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/LaunchingInstruments.html
Try running your app in Instruments with the Leaks or Allocations filter to see what is causing your issues. Hopefully, that will lead you to the source of your memory leak(s).
I understand the fact that stack grows upwards and heap grows downwards or vice-versa (architecture dependent).
But, i couldn't find much details about how actually it's implemented, my doubt is, for every process a memory block will be allocated, but is there a restriction on, how much max chunk can be used for stack or heap? Or are there no restrictions till whole allocated memory is consumed?
Yes, processes have predetermined stack sizes. Have you ever tried to recurse a method/function too much? You get a StackOverflow exception. That doesn't mean you've already went through your entire computer's memory. The OS controls distribution of stack and heap memory for each process.
I am developing sniffer using WinPcap. As am running application continuously, after 6 hours RAM is becoming full and it is not responding. why the memory increasing continuously?
Is const u_char* pkt_data is occupies memory each time?
Which variable is occupying memory continuously in Pcap API's? if so how to free the memory?
Is const u_char* pkt_data is occupies memory each time?
No. The memory pointed to by pkt_data is not guaranteed to remain allocated after your callback routine returns (if you're using pcap_loop() or pcap_dispatch()) or after the next call to pcap_next() or pcap_next_ex(). In WinPcap, there's a fixed-size circular buffer into which packets are placed in the kernel, and those are read into a single fixed-size buffer in the library.
Which variable is occupying memory continuously in Pcap API's?
None. As nos indicates, it's probably a memory leak in your program.
Ok. so my understanding of how executables are laid out in memory is... image a square box that represents the memory accessible by your app.
The program code resides at the bottom of the memory, the stack is allocated to a spot just beyond the program code and is allocated upwards. the heap starts at the top of the memory and is allocated downwards.
If this is the case, why is it possible to allocate more heap memory than stack memory?
Because even on modern systems with lots of virtual memory available, the maximum size of the call stack is usually deliberately limited to, say, 1MB.
This is not usually a fundamental limit; it's possible to modify this (using e.g. setrlimit() in Linux, or the -Xss flag for Java). But needing to do so usually indicates an abnormal program; if you have large data-sets, they should normally be stored on the heap.
I use instruments to trace memory usage of some iOS app, such as Path,Instagram,Facebook.
I find that while a foreground app take too much memory resulting very tight "Physical Memory Free". And while memory free reaches its lower boundary, maybe 10M, the system starts to reduce background app's memory size, for example Path drops memory from about 70M to 40M progressively.
I am wondering how this happened, and I found that my own app doesn't behavior this way while in background. What I should do to make my app able to reduce it's memory footprint in background if needed?