简体   繁体   English

可可记忆使用率

[英]Cocoa Memory Usage

I'm trying to track down some peculiar memory behavior in my Cocoa desktop app. 我试图在我的Cocoa桌面应用程序中跟踪一些特殊的内存行为。 My app does a lot of image processing using NSImage and uploads those images to a website over HTTP using NSURLConnection. 我的应用程序使用NSImage进行了大量图像处理,然后使用NSURLConnection通过HTTP将这些图像上传到网站。

After uploading several hundred images (some very large), when I run Instrument I get no leaks. 上传几百张图片(有些非常大)后,当我运行Instrument时,没有泄漏。 I've also run through MallocDebug and get no leaks. 我还通过MallocDebug运行,没有泄漏。 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. 当我详细查看它们时,它们被标记为“ Foundation”所有,并通过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. 在HTTP上传期间,我正在使用NSMutableData创建一个帖子正文,因此我猜这些是Cocoa在创建NSMutableData对象时为我缓存的缓冲区。

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. 我90%的肯定是我发布的正确(并且Instruments和MallocDebug似乎证实了这一点),但是我认为出于性能方面的考虑,由于我分配了许多MSMutableData缓冲区,因此Cocoa保留了这些建议。

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. 正如Instruments所说,这些块归Foundation所有,因为Foundation对象NSConcreteMutableData创建了它们。 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. 这些可能是NSData故意保留的某种高速缓存,但无法知道它们是什么。

If you believe this is a bug, you should report it at http://bugreport.apple.com . 如果您认为这是一个错误,则应在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? 另外,这可能是一个愚蠢的问题,但是您为Object Alloc工具使用哪个选项? All objects created or Created and still living? 所有创建或创建的对象仍然存在吗? You might be looking at allocations that don't matter anymore. 您可能正在查看不再重要的分配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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