簡體   English   中英

如何確定iPhone中我的應用程序分配了多少內存

[英]How to determine how much memory allocated by my app in iphone

我在我的應用程序中遇到內存泄漏的麻煩。 我只是想知道,是否有可能確定我的應用程序在堆上分配了多少內存,以便我可以相應地減少資源。 我知道系統會發出內存不足警告,並且我可以在那里清理數據,即使有時不會發生。 如果我知道我的應用程序正在達到最大內存和堆上的剩余大小,那么我可能會更好地減少我的資源。

提前致謝....

使用儀器。 XCode中的Command-I可在Instruments中分析您的應用程序。

是的,當然,我建議使用儀器的“泄漏”工具。 它可以讓您知道為應用程序分配了多少內存,如果有泄漏,它會告訴您它們是什么,何時以及何時被分配(顯然沒有釋放)。

這是我一段時間前使用的不錯的指南。 http://www.cimgf.com/2008/04/02/cocoa-tutorial-fixing-memory-leaks-with-instruments/

#include <mach/mach.h>          // freeMemory
#include <mach/mach_host.h>     // freeMemory
#include <mach/mach_time.h>     // time metrics


        struct task_basic_info info;
        if(dump_memory_usage(&info)) {
            (size_t)info.resident_size;
            (size_t)info.virtual_size;
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM