I'm testing on an iPhone 4 running iOS 7.1 attached to Xcode 5.1.1. I don't understand why I am getting memory warnings and even crashes when instruments shows my app is only using a few megabytes and there is plenty of memory free (see attached). Any ideas?
Update:
In instruments, as I suspected, I found no leaks, but the "Anonymous VM" size seems unduly large and filled with image data. Each table cell in my app displays a JPEG. Perhaps I should be pre-scaling these images and that is the cause of the large Anonymous VM size... More investigation to be done.
It turned out images displayed in UIImageViews in each and every table cell were being stored in memory at their full size, not the scaled size (size of the UIImageView). This only showed up in the "Anonymous VM" in Instruments (since iOS only stores references to your images in your application heap and the actual image caches are in system memory it seems), not in the basic memory usage displayed in Xcode. I resolved the issue by pre-scaling my images before putting them into the UIImageViews of the table view cells. There were no leaks.
Instrument is sometimes imprecise about the real memory used. The best way to measure is to print the memory usage on the console.
I found the code on this thread: Programmatically retrieve memory usage on iPhone
Related
I'm using the AssetManager class in Starling to load a lot of textures, around 600-700 png-files. All files are not loaded on start and I use multiple AssetManagers to hold the images. On start it loads around 70 images to 3 different managers and while it's loading I get some memory warnings on iOS.
iPhone appName[644] : Received memory warning.
iPhone appName[644] : Application received a memory warning from the system.
iPhone SpringBoard[74] : Received memory warning.
iPhone MobilePhone[199] : Received memory warning.
I've tried to load them at the same time and tried start each load when the other one is completed. I've also tried System.gc(); and System.pauseForGCIfCollectionImminent(0.1); between each load, this fixed the problem on iPhone 5 (7.0.4) but not on an iPhone 3gs (6.1.3).
Starling version: 1.4.1
Anyone got any tips on how to solve this?
Typically from a mobile development standpoint there is never a "one size fits all" solution. There are many different screen sizes and hardware configurations. In order to combat this many developers will generate -as mentioned previously, Sprite Sheets. Using this method the application only has to load one image vs -in your case hundreds. Image loaders take quite a while connecting to a memory address to initiate a texture upload to the GPU -I can't even image how slow it must be for that many assets.
This texture packer is phenomenal, and also aides with another feature many dev's incorporate. Asset Densities. Wherein the iPhone 3Gs a dev will load a set of sprite sheets developed for smaller screen sizes, a larger sprite sheet with twice the sized assets will load for a tablet or some of the higher end devices. This method will not only solve your memory issues but make your application look much better over a broader range of devices.
Here is a link to the Starling Wiki on multi-resolution development.
Of all the changes you can make to a project "for the better" the ones mentioned above are very high on the list.
You should NOT be loading 600-700 images. Even if they load successfully, you'll have a lot of problems with the performance. Instead, use atlas/sprite sheets.
http://wiki.starling-framework.org/manual/textures_and_images
And for even more optimized work, use ATF Textures instead png.
http://wiki.starling-framework.org/manual/atf_textures
If you run XCode Instruments against your app you'll see the total load of the device, which is the real metric that determines how often you receive memory warnings.
If your total load % is above 80%, expect a slew of constant memory warnings. The GC will try and run every time causing drastic clipping in framerate.
There's a bug about this and Adobe is working on it, but the main solution is to simply use less memory. Downscale textures for devices that have lower resolutions, etc...
https://bugbase.adobe.com/index.cfm?event=bug&id=3649713
I'm creating an iOS app with some preloaded data which includes images, it will have between 150 and 200 images. This images are not downloaded from a server, since the app won't connect to the internet.
I'm wondering about if saving the images locally can cause any problem, what is the max size that I can use to store them? Can this affect the app's performance? Anything else that I should be aware of?
Thanks in advance!
Over the air cellular maximum download is now 100MB since the iOS 7 launch.
Your maximum app size is 2GB with a maximum binary size of 60MB. With 200 images I don't think you'll hit the 2GB mark, so long as you use the proper compression techniques.
The only thing that would affect your app's performance is the way the images are presented. If they're really large images, 10+ MB you'll most likely hit memory problems in older devices and if you go larger, memory problems in newer devices. There's plenty of techniques like tiling in a scroll view to get around these problems but it requires you splice up your images and create multiple resolution versions of the image.
If your app is greater than 50MB (at the time of writing) because of the images being included then users will need WiFi to install it.
Other than that, your performance concerns should be around how many of the images you will have loaded into memory at any one time and how you can reduce that number.
My app crashes with low memory warning on device, even though the max live bytes in instruments is 3 MB tops. I do use a lot heavy PNG's in my app(in about 20 ViewControllers) , I believe ARC should've taken care of it.
Here is the screenshot.
Reduce size of heavy png files. Png file must be good in resolution but size must be less not more than 2 MB.I also had the same problem but used Three 20 Framework which solved my issue because it manages Images files allocation perfectly. Now a days it seem Three 20 is not getting updated but still you can try it in a sample app if you want . Here is the link :http://three20.info/
I figured it out myself. The problem was that I was doing animation using a bunch of PNG's.
So when using this
image.animationImages=imageFrames;
it was caching all the images in memory each time it was called, which led to dirty memory filling up and crashing the application. So, after using it each time to release the image cache we need to do this
image.animationImages=nil;
In my app, it seems like CG image is eating up a lot of dirty memory:
Is there any API to call to flush all the dirty image in the memory? In the code I am just resizing the images with this library, and I am putting only about 20 MB worth of pictures (no more than 1MB each) on the screen.
It works okay on regular iPad but it crashes on iPad mini. Can anyone point me to the right direction?
Edit: Static analyser said the project is fine. Low memory crash log is here.
Currently I am writing an iPad app. I am using a lot of images in this app around 40 MB of images!
This app works fine in simulator but crashing on device. I think the problem is with memory.
I wanted to know how much memory I can use on iPad?
Thanks
Saurabh
Remember that 40MB of image files on disk is far more when put in memory. On disk they are compressed but once you load it into memory you use just as much memory as a uncompressed image. If I remember right its (width x height x (bits per pixel/8)) = mem usage so for a full screen image (1024x768x(16/8)) = 1,572,864 so around 1.5 MB of RAM while on disk it may only be a couple hundred KB.
The iPad has 256 MB of memory, and of which, only around 100 to 120 are usable in an application. Note that this number is variable as the VM releases memory from previous applications, and could be less if you're using apps like iPod in the background.
My suggestion, look at what you can do to reduce the size of your images, through different resolutions, lower quality images, or such.