0

I am creating about 100 uibuttons and each one has a unique image( the images are some 60x70 png images).I have a problem with the memory.I would like at some point to release this memory, at the point i have finished using this buttons.

I set the images this way.

[button1 setImage:imageButton1  forState:UIControlStateNormal];

where

button1=[UIButton buttonWithType:UIButtonTypeCustom];

Now what i am trying to do is to set the image used by the uibuttons to nil as follows.

[button1 setImage:nil forState:UIControlStateNormal];

But this way, the memory remain the same.

theone
  • 1
  • 1

2 Answers2

0

If you're done with the button, can you just get rid of it entirely?

[button1 removeFromSuperview];
Joel
  • 15,654
  • 5
  • 37
  • 60
  • I think he just want to remove Button's Image?Not to remove from View – Fire Fist Feb 03 '13 at 16:27
  • well he said he was "finished using this buttons" so I would think if you're finished you're finished with the button all together. – Joel Feb 03 '13 at 16:28
  • Sorry...I just want to remove the button's image. – theone Feb 03 '13 at 16:38
  • The cached images will be cleared by the OS. http://stackoverflow.com/questions/5986177/is-there-a-way-to-clear-the-cache-used-by-uiimage-class – Joel Feb 03 '13 at 17:04
0

Pretty hard to succeed in that, of course, the problem is about memory occupation by images. On which device are you testing your application?
Your images are about 60x70px in retina and I guess the half in normal display. Are you using them in this resolution?, maybe you could scale them a little bit more. 100 buttons means that probably you are using a UIScrollview, I would suggest you to use something such as a UITableView or UICollectionView(only ios6), that reuses their cells and can help you loading images lazily only for buttons on screen, just showing images for buttons visible on screen.
Hope this helps

Andrea
  • 26,120
  • 10
  • 85
  • 131
  • I am testing my app on the iPhone4s...I am using a UIScrollView and here i add my buttons...My UIImages are created inside my app with 60x70px...Thanks for your reply.. – theone Feb 03 '13 at 17:07