Why Doesn't UIWebView release all of its memory?
I have a graphic-intensive iPad app that features a UIWebView. Using the simulator (iOS 4.2.1), I can see Real Mem increase quite a lot as I browse. The more I browse, the more RAM it uses. When I close the UIWebView and release it, some of the memory it used is freed, but not all of it. This is annoying. Okay, so maybe it's because it isn't deallocated right away. Fine. But then I would expect the system to do some cleanup when there's a memory warning. However, if I browse around, then close the UIWebView (and release it), then trigger a memory warning in the simulator, Real Mem does not change! WTF?
So why is this? Why isn't UIWebView bet开发者_运维问答ter at releasing memory back to the system? And why doesn't it appear to respond to memory warnings? Am I missing something?
Adding as an answer since it seemed to have helped:
Activity Monitor is useless for debugging purposes. Use Allocations Instrument. Note that the simulator can behave significantly differently than an app on the device.
Happy to have helped. I often find that turning on "Only track live allocations" is quite helpful for watching the ongoing working set of my applications. Live/dead tracking is useful, too.
Oh, and heapshot analysis (article on my weblog) can be extremely effective in tracking down memory leaks.
Leaks? Never use it. Heapshot analysis entirely replaces it for me. Your mileage may vary.
精彩评论