简体   繁体   English

以编程方式检查内存使用情况(Cocoa)

[英]Programmatically checking memory usage (Cocoa)

I'm trying to find a way of limiting the amount of memory a particular custom object is using, based on how much memory is left. 我试图找到一种方法来限制特定自定义对象使用的内存量,具体取决于剩余的内存量。 The most useful way of doing this would be some kind of method or function that checks to see how much memory a given C Object is using. 执行此操作的最有用方法是使用某种方法或函数来检查给定C对象使用的内存量。 This way the program can reject the creation of further data when the object reaches its preset limit, rather than going ahead and creating it then dealing with the memory warning in retrospect. 这样,当对象达到其预设限制时,程序可以拒绝创建更多数据,而不是继续创建它,然后回顾处理内存警告。

Does anyone know of Cocoa methods that: A) Return how much memory is being used by a given object B) Return how much more memory the system can use up before it generates a warning 有没有人知道Cocoa方法:A)返回给定对象使用的内存量B)返回系统在生成警告之前可以消耗多少内存

-Ash -灰

A. You can get size of an object using malloc_size(myObject) (you need to traverse all the nested objects too). malloc_size(myObject) :您可以使用malloc_size(myObject)获取对象的大小(您还需要遍历所有嵌套对象)。 Also check docs for NSCache. 还要检查NSCache的文档。

B. No, there is no documented way to do that B.不,没有记录的方法可以做到这一点

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

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