1

I am a new programmer and I am learning swift myself. I was programming an app that has to manage a lot of images. I am using Photo.image = UIImage(named: "something"), but I think I am having memory issues because every time I switch between pages memory usage jumps with 30MB. The peak total memory usage is about 150MB. First: Is this normal and should I be worried about this?

I am suspecting that unused objects that are created are not cleared (or released). I went through some material, but I could not find anything helpful. Can someone tell me how to manage memory by myself? Or should I use something other than UIImage?

Here is an snapshot from memory leaks analysis tool:

  • This is probably standard behaviour for `UIImage` provided you are showing different images on different pages (your terminology). `UIImage` caches images so your memory usage will increase until it is cleared after a `low memory warning`. However, if you don't want to cache images there are alternatives. See this answer - it is old but still relevant: http://stackoverflow.com/questions/316236/difference-between-uiimage-imagenamed-and-uiimage-imagewithdata . The `Leaks` tool should enable you to identify which objects are holding large amounts of memory. – Robotic Cat Apr 24 '16 at 21:27
  • I know that UIImage cashes images, but I am asking if is there any way that I can clear that memory that is used to keep those images when I switch between pages (view controllers). //My app is a basic hangman app. In the first view controller, the user selects the character, and in the second view controller, the user plays the game. Every character has images of his own. – Klaus Çipi Apr 24 '16 at 22:00
  • Not to my knowledge - the cache is managed by the OS. *IF* the memory usage is causing a problem then simply do not cache in the first place. If the memory usage is not causing a problem then I would not bother about it. – Robotic Cat Apr 24 '16 at 22:02

0 Answers0