MattStacey
MattStacey

Reputation: 895

UIImageView - Real Memory Usage continually increases

I have one UIImageView that I use to display different images at different points in time. When I want to change the image displayed I use the following code (where filenamePng holds the image name to be loaded and imgView is my UIImageView):

    [self.imgView setImage:[UIImage imageNamed:filenamePng]];

When I look at the 'Real Memory Usage' of my app in Instruments, as different images are displayed, the memory just continues to increase (some of the png's are quite large so its easy to tell), I have played around with setting the UIImageView to nil/releasing the it but to no avail.

Can someone give me an indication as to why when using the above code it appears that previous images in memory are not released even when set to nil/released?

Upvotes: 1

Views: 370

Answers (1)

justin
justin

Reputation: 104698

+[UIImage imageNamed:] uses a cache. Assuming all your ref counting is correct, it should purge at some point. Also, the execution on sim vs device can be much different in this regard.

Upvotes: 1

Related Questions