0

My app take a screenshot about my view. The code works but the profile/allocations tool shows that memory isn't released the context. Here is some code about this:

CGRect rect = CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height);
UIGraphicsBeginImageContext(rect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

[self.view.layer renderInContext:context];   //allocations tool shows 49.6% alert here!


UIImage *wallpaper = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

I tried to use autorelease{} but nothing works... So my app memory usage is getting higher and higher after this action, I don't know how to release this context. I'm using ARC.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
madG
  • 13
  • 4
  • Where is that code? Inside a `[UIView drawRect:]` or not? – trojanfoe Nov 14 '13 at 10:52
  • The code I mentioned is the above code. It generates the screenshot, no problem with it! – madG Nov 14 '13 at 10:57
  • I'll repeat the question then: Is it inside a `[UIView drawRect:]` method or not? – trojanfoe Nov 14 '13 at 10:58
  • not! it's not inside of this – madG Nov 14 '13 at 11:03
  • Does this question help? http://stackoverflow.com/questions/4970627/releasing-renderincontext-result-within-a-loop – trojanfoe Nov 14 '13 at 11:06
  • Or this one? http://stackoverflow.com/questions/2785401/renderincontext-creating-memory-that-is-not-promptly-released – trojanfoe Nov 14 '13 at 11:09
  • I have seen this question before. It's seemed a good answer (however it's not ARC), but nothing worked for me about it. – madG Nov 14 '13 at 11:15
  • I can't understand if I use the autorelease {} for the above code, than why those staffs isn't released from the memory?!?! – madG Nov 14 '13 at 11:44
  • the closest question to my one is: http://stackoverflow.com/questions/19646833/renderincontext-taxes-app-memory – madG Nov 14 '13 at 11:47
  • This has nothing to do with `autorelease`. autorelease is _not_ a method for freeing memory, it is a method for _preventing_ premature deallocation. read the links @trojanfoe posted. – Brad Allred Nov 14 '13 at 15:51

0 Answers0