I have a memory leak from 3 UIImages the problem is I can’t just release them anywhere in my code because they are getting used in many different spots at all times and I don’t know where it all is (over 20,000 lines of code) so my question is if say every 10 seconds I take one of those UIImages, create a blank placeholder UIImage, set that blank UIImage’s image to be the original UIImage’s image. Release the original UIImage, Now set the original UIImage’s image equal to the placeholder UIImage and then release the placeholder UIImage, will this work? If I set a UIImage a thousand times and then release it at the very end does it clear all the data or do I have to release it a thousand times?
Share
I don’t really understand what you want to do but you only have one solution anyway: fix the memory leak. Everything else is likely just moving your issues around until everything falls apart.
Since you seem to have leaks you likely don’t follow the Apple memory management guidelines strictly enough. It’s vital that you read, understand and obey to this document, it’s probably the most important document regarding iOS development that you need to understand. If you do, you can keep even huge projects absolutely memory leak free. If you don’t, you’ll end up with leaks and crashes.
Luckily Apple already can help you find a lot of issues: Press “Analyze” in Xcode and fix all issue that the static analyzer finds. Except for a few rare exceptions, the issues that are reported by the analyzer are real problems that need to be fixed. Same goes for compiler warnings, BTW. Your project should yield not a single warning and not a single static analyzer issue, no matter how big your app is (I can tell you from first-hand experience working on an app with several man years of work that this not only is possible, it’s the only way to keep sanity).
If the static analyzer doesn’t find the memory mismanagement you’ll need to bite the bullet and analyze all the spots where the images are used by hand and maybe rewrite a few classes. Every workaround will just shift the work you’ll need to do to a later time and maybe even make matters worse.