ios - 如何使用 Xcode 跟踪哪个项目增加了 iOS 中的内存?

标签 ios objective-c xcode ipad memory-management

我有一个 iOS 应用程序有 5 个 View Controller

在 Debug模式下,它从 30mb 内存使用开始,然后当我使用应用程序并转到其他 View Controller 时,它增加了 5 或有时更多。永远不要失望。

我使用 sqlite 数据库和 我使用单例类:

#import <Foundation/Foundation.h>

@interface LoggedinUser : NSObject
{
   NSMutableArray *questionIDs;
}
+ (LoggedinUser *)sharedCenter;
@property (nonatomic,retain) NSString *email;
@property(nonatomic,retain)NSString *firmID;
@property (nonatomic,retain) NSString *name;
@property(nonatomic,retain)NSString *surname;
@property (nonatomic,retain) NSString *userTypeID;
@property(nonatomic,retain)NSString *firmName;
@property(nonatomic,retain)NSString *userID;
@property(nonatomic,retain)NSString *dbFileName;
@property(nonatomic,retain)NSString *answerdbFileName;
@property(nonatomic,retain)NSString *lastOrderIndex;
@property(nonatomic,retain)NSMutableArray *questionIDs;
@property(nonatomic,retain)NSString *programID;
@property(nonatomic,retain)NSString *merchantID;

@property(nonatomic,retain)UIViewController *myQuestionView;
@end


#import "LoggedinUser.h"

@implementation LoggedinUser
@synthesize             userID,surname,name,userTypeID,email,firmID,firmName,dbFileName,answerdbFileName,lastOrderIndex,programID,questionIDs,merchantID,myQuestionView;

static LoggedinUser *sharedLoggedinUser = nil;    // static instance variable

+ (LoggedinUser *)sharedCenter {
    if (sharedLoggedinUser == nil) {
    sharedLoggedinUser = [[super allocWithZone:NULL] init];
    }
return sharedLoggedinUser;
}

- (id)init {
if ( (self = [super init]) ) {
    questionIDs = [[NSMutableArray alloc] init];
    myQuestionView=[[UIViewController alloc] init];
}
return self;
}

+ (id)allocWithZone:(NSZone *)zone {
    return [self sharedCenter];
}

- (id)copyWithZone:(NSZone *)zone {
    return self;
}

-(void)dealloc {
    //[super dealloc];
}

@end

可能这可能是我的问题,但我想在浏览我的 View Controller 时跟踪哪个变量或哪个方法增加了内存。

注意:如果我在 View Controller 上什么都不做,它永远不会增加。在我推送到另一个 View Controller 后它会增加

它是一个 iOS 7 应用程序并使用 ARC

请给我一些想法,找出什么是找到问题的正确方法,如何跟踪变量和方法以找出导致问题的方法

编辑:@Mutawe 这是我的 Instruments 屏幕截图,我在统计中找不到对象列表?你能帮忙吗? screenshot

最佳答案

  • 打开你的 Xcode 项目
  • 选择可执行文件(如果需要)
  • cmd+i(配置文件)
  • 在 Le Wizard 中选择“Leaks”工具(如果需要)
  • 按 Return 键开始分析
  • 运行您的应用
  • 在仪器中按“停止”
  • 确认选择了“分配”工具
  • 点击并按住名为“统计”的弹出按钮
  • 选择对象列表项
  • 在对象列表的记录中找到您感兴趣的分配
  • 选择那个分配/对象
  • 单击该分配 TableView 单元格中地址右侧的“详细信息箭头”
  • 现在您可以看到与分配相关的所有事件(分配、释放、引用计数操作)
  • cmd+shift+e 获取详细信息
  • 浏览此列表中的事件,找到您要寻找的不平衡。

关于ios - 如何使用 Xcode 跟踪哪个项目增加了 iOS 中的内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25500878/

相关文章:

iphone - 将图层阴影裁剪为宽度而不是高度?

iphone - iPhone SDK 中的信用卡验证算法

ios - 是否可以在 dismissmodelviewcontroller 时返回一个值

iOS UIImageView 约束在表格单元格中不起作用

ios - 有没有办法在 SwiftUI 中创建下拉菜单/按钮?

iOS 企业版 : What should I change or keep the same so an updated app installs over the older version?

ios - swift : Map function found nil while unwrapping an Optional value

objective-c - 谁是 Cocoa MVC 文档架构中的 Controller ?

iphone - Xcode 上奇怪的编译时错误

ios - NSStackView subview 不调整子堆栈 View 的大小