views:

354

answers:

1

I have 3 UIImages in UIScrollView and I am initializing these images in the following way:

UIImage *dimage = [[UIImage alloc] initWithData:data];

Where data is a NSdata gotten from url request. After this I am caching the images. When I check memory allocation the 3 images takes up 472 Kb each and allocation has been requested by "img_data_lock" from CoreGraphics library. When I check size of that image on disk cache it was 230Kb each.

I dont know how can it take more space. I hope my question is clear.

A: 

Not sure what "disk cache" you're looking at but memory and disk usage are only weakly related. The data used to create an UIImage is only part of the data the object actually uses. This means an active object will can use more memory than the data that created it.

To further complicate things, UIImage will purge itself of image data under low memory situations so size of UIImage object can vary widely over the course of its existence.

TechZen
thanks TechZen, disk cache means "<app name>/Library/Cache" folder on device, i use that for temporary cache.<br/>so there is nothing i can do.
Nnp
I don't think you have a problem. There is very little correlation between the size of data on disk and the size of objects in memory. The UIImage object will always be bigger than the data unless it purges the data. Remember, the data is not the UIImage object itself but just a piece of it. The UIImage object has to store other information besides the raw data. That other information makes it larger than the data.
TechZen
Thanks TechZen, i was just concern about memory,when memory raised by 1MB while moving to this particular view so it drag my attention. so now i am keeping only 3 images at time in scrollview just to save memory.
Nnp