Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

annguyen

macrumors newbie
Original poster
Oct 2, 2008
15
0
I have been working on a game which using much image resources. One issue I am having with the cached and non-cached resources of UIImage.

In my game, there are almost 100 images display on a board, each image is my custom UIImageView. One of the requirements is to switch current images to others during the rotation animation. And here is what I did:
- Loop through all 100 UIImageView objects, make it rotate using CAKeyframeAnimation.
- While the rotation animation executing, load the new image (UIImage) using [UIImage imageNamed:] method to load new image, this new image will be cached
- Then call UIImageView.image=myNewImage to replace new loaded image

It works very smoothly, but the image resources are cached and my app holds too much memory. And I want to not using the system cached like that. I then not using [UIImage imageNamed:] method anymore but using the [UIImage imageWithContentsOfFile:] method instead. But the performance turns out even worse :( The new images are supposed to replace the old ones during the rotation, but the speed of loading new images is longer the rotation time. And you can imagine that the rotation animation stopped but the old images are still remained and it keep replacing one by one...

And my questions are:
1. Does anyone know why not using cache take more time to load image? While using cached, I am sure that all images are first loaded and not be reusing, the speed is way faster.

2. Is there any way to clear the system cached? As I don't need to reuse any of them in my app.

Your comments/feedback are appreciated. :apple:
 

Dual Pistolas

macrumors newbie
Nov 10, 2008
17
0
bump! I'm also looking for the answer to this. It seems like using imageNamed doesn't ever allow you to unload the image. If you keep loading in images using this method, it eventually runs out of memory and crashes. I also found initWithContentsOfFile to be the only option, but it takes 50% longer to load all my assets.

Does anyone have the solution for this?
 

rsud

macrumors newbie
Mar 28, 2009
1
0
why are you loading during the animation...???

why aren't you perloading the images at startup time???
 

Dual Pistolas

macrumors newbie
Nov 10, 2008
17
0
why aren't you perloading the images at startup time???

Sometimes, you might want to load more images than the memory can hold at once. For example, the art assets for a level in a game. In this case, you have to unload level 1's assets before you load level 2's.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.