Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Spiky Memory "Healthy" for App?

I've recently been developing an app that processes a large amount of data very frequently (~15 times a minute). To do so, I allocated a large chunk of memory, then freed it for each batch of data.

Here's a screen of my Memory Allocations from Instruments: The memory

The Memory usage oscillates from about 3MB to about 30MB pretty quickly. I was just wondering, is this "healthy," per se for the iPhone.

Is it risky to allocate and free so much memory so quickly? Is it unsustainable, or just bad practice?

Thanks!

like image 923
pop850 Avatar asked Jan 30 '11 14:01

pop850


People also ask

Does garbage collection affect performance?

The most common performance problem associated with Java™ relates to the garbage collection mechanism. If the size of the Java heap is too large, the heap must reside outside main memory. This causes increased paging activity, which affects Java performance.


1 Answers

It is neither risky nor necessarily bad practice. Allocating and freeing memory takes time, so doing it very frequently vs. doing it once and re-using the allocated memory is a trade-off between memory usage efficiency (using the lowest amount of memory at every single moment) and performance.

If the performance of your app doesn't suffer at the moment, you have probably made the correct choice regarding this tradeoff for your app.

Generally speaking, using 30 MB of memory is quite a large amount for older devices (iPhone 3G and older). You cannot be sure that your app has that much memory available so be prepared to received memory warnings. If your app cannot reduce its memory usage when it receives a memory warning, the OS might kill it.

like image 200
Ole Begemann Avatar answered Oct 17 '22 05:10

Ole Begemann