iOS上的活动监视器中的实时字节与实内存 [英] Live Bytes vs Real Memory in Activity Monitor on iOS

查看:263
本文介绍了iOS上的活动监视器中的实时字节与实内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iOS应用程序,它会创建很多小对象和花车,并试图了解它消耗的内存使用量。

I'm working on an iOS app that will create a lot of small objects and floats, and trying to get an idea for how much memory usage it's consuming.

当我运行Allocations仪器时,它说我有大约2MB的Live Bytes,当我在应用程序中移动时,这个数字大致保持不变(当应用程序繁忙时,峰值达到3MB左右,但随后下降回到2MB)。

When I run the "Allocations" instrument, it says I have about 2MB of "Live Bytes", and the figure stays roughly constant as I move through the app (spikes up to 3MB or so when the App is busy, but then drops back down to 2MB).

但是当我运行Activity Monitory乐器时,我的应用程序的真实内存在完成启动后为25MB,并且在绘制时会快速增长发生在我的CALayer中。在不到一分钟的时间内,它超过100MB。

But when I run the "Activity Monitory" instrument, my app's "Real Memory" is 25MB once it finishes launching, and grows rapidly whenever drawing occurs inside my CALayer. In less than a minute, it goes over 100MB.

为什么Live Bytes显示2MB,但Real Memory显示100MB?

Why would "Live Bytes" show 2MB, but "Real Memory" shows 100MB?

我的CALayer正在绘制路径,它将CPU固定在100%几秒钟,只是为了完成一次绘制操作,并且它正在加载所有这些点将NSData对象转换为CGPoint值,然后再次释放它们(NSData对象是正在绘制的点的压缩版本,将增量从一个点存储到下一个点,所以我将它保存在RAM但不保留实际的CGPoints) 。

My CALayer is drawing tons of paths, it pegs the CPU at 100% for a few seconds just to finish a single draw operation, and it's loading all of these points out of an NSData object into CGPoint values, then deallocing them again (The NSData object is a compressed version of the points being drawn, storing deltas from one point to the next, so I keep it in RAM but don't keep the actual CGPoints).

它还将绘图的结果缓存在UIImage中,并且这些数据保存在先进先出的数组中,该数组不会增长到超过大约500KB。

It also caches the result of the drawing in a UIImage, and these are kept in a first-in-first-out array that won't grow to more than about 500KB.

推荐答案

事实证明我的问题是 NSZombieEnabled

编辑方案>运行>参数>环境变量中禁用该功能解决了额外的内存使用问题。

Disabling that in Edit Scheme > Run > Arguments > Environment Variables solved the extra memory use.

这篇关于iOS上的活动监视器中的实时字节与实内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆