简体   繁体   中英

Is memory pressure the same as memory leaks?

我正在开发一个显示图像的应用程序,由于iPad 2上的内存压力很大,我正在终止应用程序。所以我想知道内存压力和内存泄漏是否相同?

They can be related.

Memory leaks is memory you can never get back. If your project uses ARC then memory leaks are pretty rare.

Sort of similar to memory leaks are reference cycles (or retain cycles with MRC). This is memory that isn't a classic leak but it is wasted memory for objects that can't properly be deallocated.

Memory pressure is your app simply taking up too much memory. This can be caused by using too much memory. Examples could be opening and trying to use too many large images or loading too large of a file into memory. And of course, leaks and reference cycles waste memory over time. These could eventually lead to your app using too much memory.

Use the Allocations and Leaks tools of Instruments and find the cause of the problem. Leaks are easy enough to spot. Reference cycles are a little harder. You have to watch the memory footprint and see if it keeps climbing over time as your app is used. Look at the objects in memory. If you dismiss a view controller yet Instruments still shows that there is a live instance of that view controller, then you have a reference cycle keeping it alive. That needs to be fixed.

If you are simply loading too many images at once, it is neither a leak nor a reference cycle, then you need to find another solution to avoid loading too much at once.

I am not familiar with memory pressure, but I do focus on fixing some memory leak. memory leak means that the memory allocated cannot get back. for example, a point variable which point to a memory block point to another memory block, the first memory block is leaked, which can not be get back ever. thus, you apps apply for more and more memory without releasing what it already have applied. It may also casue memory pressure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM