可可内存使用情况

发布于 2024-08-27 14:48:48 字数 653 浏览 5 评论 0原文

我试图在我的 Cocoa 桌面应用程序中追踪一些特殊的内存行为。我的应用程序使用 NSImage 进行大量图像处理,并使用 NSURLConnection 通过 HTTP 将这些图像上传到网站。

上传数百张图像(有些非常大)后,当我运行 Instrument 时,我没有发现泄漏。我也运行过 MallocDebug,没有发现任何泄漏。当我使用 Instrument 深入研究对象分配时,我得到如下输出:

GeneralBlock-9437184, Net Bytes 9437184, # Net 1
GeneralBlock-192512, Net Bytes 2695168, # Net 14

等等,对于较小的尺寸。当我详细查看这些时,它们被标记为由“Foundation”拥有并通过 NSConcreteMutableData initWithCapacity 创建。在 HTTP 上传期间,我使用 NSMutableData 创建一个帖子正文,所以我猜测这些是 Cocoa 在我创建 NSMutableData 对象时为我缓存的缓冲区。

有没有办法强制 Cocoa 释放这些?我 90% 确信我的发布正确(Instruments 和 MallocDebug 似乎证实了这一点),但我认为 Cocoa 出于性能原因保留了这些,因为我分配了如此多的 MSMutableData 缓冲区。

I'm trying to track down some peculiar memory behavior in my Cocoa desktop app. My app does a lot of image processing using NSImage and uploads those images to a website over HTTP using NSURLConnection.

After uploading several hundred images (some very large), when I run Instrument I get no leaks. I've also run through MallocDebug and get no leaks. When I dig into object allocations using Instrument I get output like this:

GeneralBlock-9437184, Net Bytes 9437184, # Net 1
GeneralBlock-192512, Net Bytes 2695168, # Net 14

and etc., for smaller sizes. When I look at these in detail, they're marked as being owned by 'Foundation' and created via NSConcreteMutableData initWithCapacity. During HTTP upload I'm creating a post body using NSMutableData, so I'm guessing these are buffers Cocoa is caching for me when I create the NSMutableData objects.

Is there a way to force Cocoa to free these? I'm 90% positive I'm releasing correctly (and Instruments and MallocDebug seem to confirm this), but I think Cocoa is keeping these around for perf reasons since I'm allocating so many MSMutableData buffers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不回头走下去 2024-09-03 14:48:48

如果您确定正确地释放了您拥有的对象,那么您实际上无能为力(或应该)做什么。正如 Instruments 所说,这些块归 Foundation 所有,因为 Foundation 对象 NSConcreteMutableData 创建了它们。这些可能是 NSData 故意保留的某种缓存,但无法知道它们是什么。

如果您认为这是一个错误,您应该在 http://bugreport.apple.com 上报告该错误。内存所有权的规则也适用于不能很好地管理内存的类。

另外,这可能是一个愚蠢的问题,但是您对对象分配工具使用哪个选项?所有已创建或已创建且仍然存在的对象?您可能会看到不再重要的分配。

If you're certain you're releasing the objects you own correctly, then there's really nothing you can (or should) do. Those blocks are, as Instruments says, owned by Foundation because NSConcreteMutableData, a Foundation object, created them. It's possible that these are some sort of cache that NSData is keeping around on purpose, but there's no way to know what they are.

If you believe this is a bug, you should report it at http://bugreport.apple.com. The rules of memory ownership apply to classes that don't manage memory well, too.

Also, this might be a silly question, but which option are you using for the Object Alloc tool? All objects created or Created and still living? You might be looking at allocations that don't matter anymore.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文