overall bytes in Xcode Instruments reaches 1 GB is that ok? - ios

Here is my question.
I tried to check my allocation part using Instruments in xcode.
I am doing some image crop Application using CGImageSourceCreateThumbnailAtIndex for processing the images. while doing the process it is taking to much memory and i released it in right manner.
In Instruments the live bytes is 1.56Mb , #living = 22,862 and Overall bytes reaches 1.11Gb after that also it will increase.
This application is not working in ipad1. i dont have ipad2 or 3 in hand to test the application.
In the image some peak points are there. At that point Live Bytes reaches 73MB. and it will be released. will ipad 2 handle this peak ??
Can anyone tell this will cause any memory Problem in device.
How about the overall bytes. is there any limit for this?

yes since overall bytes is just the number of bytes that were EVER allocated.
The longer the app runs, the higher the no.

Related

Xcode Memory Graph - showing increasing memory use - what exactly does it show?

When watching the debug graph in xcode 6 (and probably 5 too), when running my application the memory use continues to rise as I place more of a certain object on the screen and animate it's movement. It does not seem to decrease when I remove it. Once removed I believe there are no more references to them.
See screenshot:
http://i.stack.imgur.com/SnhbK.png
However when I use Instruments to try to identify what's going on, there's only around 12mb persisting, and Total Bytes continues to rise, as expected.
See screenshot:
http://i.stack.imgur.com/VBwce.png
Is this normal behaviour? What exactly is the graph in Xcode showing? Am I overlooking something?
In Instruments I have Allocation Lifespan set to All Allocations and Allocation Type set to All Heap and Anonymous VM for the screenshots above.
UPDATE
By running Instruments with Activity Monitor I was able to see that the "Real Memory" was increasing at the same rate as is displayed in Xcode. #Mark Szymczyk pointed out that OpenGL ES Texture memory allocations are not shown in the Allocations instrument.
By purging the texture cache with the following command in Cocos2D 3.1 at regular intervals, memory use consistently drops back down to around 18mb and begins increasing again as I add more sprites.
[[CCDirector sharedDirector] purgeCachedData];
Credits go to Mark Szymczyk for pointing me in this direction - thanks!
Looking at your screenshots, the Xcode graph is probably showing the equivalent of the Total Bytes column in your Instruments screenshot. When you remove an object, the persistent bytes will decrease, but the total bytes won't. That would explain why the memory use never goes down in the Xcode graph.
The Persistent Bytes column in Instruments is what you should be looking at to determine your app's memory usage.

App keep crashing due to memory pressure

My app is saving and retrieving data from Parse.com. And showing images, buttons, scrollviews, etc.. (the normal stuff). Then when I got near finishing my app, it started to receive memory warnings and the app started crashing often. I checked it in the Instruments and noticed the live bytes was extremely high at some points, and I can't figure out why.
Is the app crashing because of the high live bytes? What should value of the live bytes be?
Obiously something is going on in the VM. But I have no idea what this is. What is the VM: CG raster data? And this: VM: CG Image? I am not using CGImages only UIImages
Is the app crashing because of the high live bytes?
Yes.
What should value of the live bytes be?
There's not fixed number. The limits change from OS version to OS version, and sometimes depend on the device and what else is going on at the moment. The right thing to do is (a) try not to use so much, and (b) heed the warnings and dispose of stuff you don't need.
Obiously something is going on in the VM. But I have no idea what this is. What is the VM: CG raster data? And this: VM: CG Image? I am not using CGImages only UIImages
A UIImage is just a wrapper around a CGImage.
You have too many images alive at the same time. That's the problem you have to fix.
So, how many is too many? It depends on how big they are.
Also, note that the "raster data" is the decompressed size. A 5Mpix RGBA 8bpp image takes 20MB of RAM for its raster data, whether the file is 8MB or 8KB.
I still feel the number is too high though, or is 30-40 MB an okey number handling 3-6 full-screen sized images at a time? This is when tested on a 4 year old iPhone4, iOS 7. If that matters.
On an iPhone 4, "full-screen" means 640x960 pixels. 8bpp RGBA means 4 bytes per pixel. So, with 6 such images, that's 640*960*4*6 = 14MB. So, that's the absolute minimum storage you should expect if you've loaded and drawn 6 full-screen images.
So, why do you actually see more than twice that?
Well, as Images and Memory Management in the class reference says:
In low-memory situations, image data may be purged from a UIImage object to free up memory on the system. This purging behavior affects only the image data stored internally by the UIImage object and not the object itself. When you attempt to draw an image whose data has been purged, the image object automatically reloads the data from its original file. This extra load step, however, may incur a small performance penalty.
So think of that 14MB as basically a cache that iOS uses to speed things up, in case you want to draw the images again. If you run a little low on memory, it'll purge the cache automatically, so you don't have to worry about it.
So, that leaves you with 16-24MB, which is presumably used by the buffers of your UI widgets and layers and by the compositor behind the scenes. That's a bit more than the theoretical minimum of 14MB, but not horribly so.
If you want to reduce memory usage further, what you probably need to do is not draw all 6 images. If they're full-screen, there's no way the user can see more than 1 or 2 at a time. So, you could load and render them on demand instead of preloading them (or, if you can predict which one will usually be needed next, preload 1 of them instead of all of them), and destroy them when they're no longer visible. Since you'd then only have 2 images instead of 6, that should drop your memory usage from 16-24MB + a 14MB cache to 5-9MB + a 5MB cache. This obviously means a bit more CPU—it probably won't noticeably affect responsiveness or battery drain, but you'd want to test that. And, more importantly, it will definitely make your code more complicated.
Obviously, if it's appropriate for your images, you could also do things like using non-Retina images (which will cut memory by 75%) or dropping color depth from RGBA-8 to ARGB-1555 (50%), but most images don't look as good that way (which is why we have high-color Retina displays).

iPad: Allocations show 3 MB memory while dirty memory continuously increases ans reaches greater than 100 MB

I am working on an iPad app that includes lots of images, animations and videos. My app crashes after running 12 to 13 minutes. Allocations show me only 3 MB memory usage while in VM Tracker dirty memory continuously increases till it reaches 130 MB and then app crashes. But VM Tracker does not give me any insight about what is actually happening in the code and which piece of code is responsible for increasing dirty memory. I am badly stuck with it. Have tried every possible thing. I am not using [UIImage imageNamed:], have avoided autoreleased objects as long as I can, have used autorelease pools where some convenience constructor is used. I am using FTUtils for animations in most places while in some places I am using [UIView beginAnimation:] but I am unable to reach any conclusion. Any help will be highly appreciated because I am badly stuck.

Strange IOS memory problems

I have a game for iOS devices. A couple of days before I got a memory problem in different devices.
What I'm doing is:
1. Delete from a device my game.
2. "Product->Clean" it in xCode.
3. Run it on the device.
4. Look at the memory in Instruments (Activity monitor).
5. Take another device.
6. Repeat from the first step.
iPad 1 with iOS 4.3.1: Game works fine, 51 MB memory is used in the main menu, 105 MB in the first level.
iPad 1 with iOS 5, iPod 4 with iOS 5: Game crashes, 77 MB in the main menu, 130+ MB in the first level.
Does anyone have the same problem? Is it because of newer iOS?
10/31/2011
Six hours of breakpoints and jumping between devices gives me this:
in iOS 4.3.1 glTexSubImage2D function, wich can be found in the openGLES.framework, never allocates any memory.
The same function in iOS 5.0 calls
glTexSubImage_Exec ->
gleSynchronizeTextureLevelOnCurrentDevices ->
gfxUploadPluginTextureLevel ->
gfxAllocateTextureLevel ->
malloc
After all, I had different pixels parameter in glTexImage2D and glTexSubImage2D, what led to additional 30% memory for each of sprites. In 4.3.1 difference in the pixels parameter was ok, but in 5.0 it is not. I don't know if it's a bug or not.
Thanks to all.
You need to figure out where your memory is actually going. Instruments is a good start, but you probably want to take heapshots at various points and compare. (I assume you have already used the Leaks instrument to identify true leaks, not just memory bloat.)

fake call to applicationDidReceiveMemoryWarning being triggered even if I have around 80 MB of RAM left

I have NSLog-ed the remaining memory in a timer repeating after 1 second. It just print the remaining memory.
The runtime requirement app is around 20 MB max. Log shows free memory 90 MB+ when I launch the app.
There is a tabBar in which one of the Tabs is having a Google Mapkit's Map.
Once the application comes in working state, RAM - 80 MB.
When I scroll through the zoomed map- BOOM!!! "applicationDidReceiveMemoryWarning" logger still shows free memory counter around 75-80 MB.
This is causing my other views data to be released.
Anyways..even if the RAM is available and when app doesn't crash.. panning in Map drastically reduce the RAM to 3-4 MBs from 70-80 MB. With this case, if app claims for memory - lets say for a captured image - BOOM Again!!! "applicationDidReceiveMemoryWarning"
Anyone have experienced this before...?? any helpful comments..?
if you've not experienced this - just try it out with Apple's weather map sample app or the Native Maps Application on ur phone!! - to see how map eats up runtime memory when we pan a zoomed map...!!
Regards,
SamFisher
That's how it's supposed to work. Memory is there to be used. Any that is not used is being wasted. As long as you have no memory leaks and you're unloading/reloading your views and caches correctly, there is no problem here.

Resources