我试图解决Swift中的内存泄漏问题。据说在给定时间应该只有UIViewController的特定子类的一个实例。我尝试通过创建跟踪创建和删除的静态变量来检测对象计数。有关示例代码,请参阅以下代码:
// AppDealsTVC.m
#import "AppDealsTVC.h"
- (void)viewDidLoad {
[super viewDidLoad];
NSDictionary *dealOne = @{kDeal: @"25% off Club Sandwich",
kDiscount: @"now $5.25",
kDImage: @"Club_San_RA.jpg",
kDDescription: @"Get 25% off our flavorful Club Sandwich!",
};
NSDictionary *dealTwo = @{kDeal: @"Grilled Cheese",
kDiscount: @"FREE (read more)",
kDImage: @"grilled_cheese_RA.jpg",
kDDescription: @"Our flavorful Club Sandwich offers a variety of tastes combined into one gorgeous looking and great tasting sandwich!",
};
NSDictionary *dealThree = @{kDeal: @"Club Sandwich w fries/chips",
kDiscount: @"FREE (read more)",
kDImage: @"Club_San_RA.jpg",
kDDescription: @"Our flavorful Club Sandwich offers a variety of tastes combined into one gorgeous looking and great tasting sandwich!",
};
self.dealListArray = [NSMutableArray arrayWithObjects:
dealOne,
dealTwo,
dealThree,
nil];
}
// RedeemVC.m
#import "RedeemVC.h"
#import "AppDealsTVC.h"
- (IBAction)redeemButton:(id)sender {
// Remove deal from the self.dealListArray
}
考虑到我有一个很大的故事板,将这些行复制粘贴到我的每个视图控制器是不切实际的。无论如何,我可以更方便地计算对象实例吗?如果没有,有没有办法将这行代码应用到我的每个视图控制器而不必修改每一个?
答案 0 :(得分:1)
使用Instruments Leaks模板。它已经为你做了这项工作。