NSArray 内存泄漏!无法获取为什么?

发布于 2024-09-27 16:40:54 字数 475 浏览 0 评论 0原文

您好,我在 Instruments 中遇到以下代码行内存泄漏。

 NSArray *itemsList=[[NSArray alloc] initWithObjects:@"Love",
     @"Hate",@"Happy",@"Sad",
     @"Desire",@"Anger",@"Hope",@"Fear",@"Silly",nil];

我正在使用下面的代码: arrayList 也在 dealloc 块中释放。

NSArray *itemsList=[[NSArray alloc] initWithObjects:@"Love",@"Hate",
    @"Happy",@"Sad",@"Desire",
    @"Anger",@"Hope",@"Fear",@"Silly",nil];
self.arrayList=itemsList;
[itemsList release];

Hi I am getting memory leak in Instruments for the following line of code .

 NSArray *itemsList=[[NSArray alloc] initWithObjects:@"Love",
     @"Hate",@"Happy",@"Sad",
     @"Desire",@"Anger",@"Hope",@"Fear",@"Silly",nil];

I am using the below code:
arrayList is also released in dealloc block.

NSArray *itemsList=[[NSArray alloc] initWithObjects:@"Love",@"Hate",
    @"Happy",@"Sad",@"Desire",
    @"Anger",@"Hope",@"Fear",@"Silly",nil];
self.arrayList=itemsList;
[itemsList release];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烧了回忆取暖 2024-10-04 16:40:54

我假设 arrayList 是在 @property 语句中使用 retain 声明的。如果没有,那肯定是你的问题。

如果是,那么您就有泄漏,但不是在您发布的代码中。重要的是要认识到,Instruments 首先显示的不一定是泄漏发生的位置,而是泄漏内存的分配位置。您将查看 arrayList 的其余用法,并找到缺少发布的保留的位置。

如果单击 Instruments 中对象内存地址旁边的箭头,您应该能够看到对象被保留和释放的所有位置。您将仔细查看它们并确定哪个保留缺少发布。

I'm assuming that arrayList is declared using retain in the @property statement. If not, then that is certainly your problem.

If it is, then you have a leak, but not in the code you've posted. It's important to realize that Instruments first shows not necessarily where the leak occurred, but where the leaked memory was allocated. You'll have look through the rest of your uses of arrayList and find where you have a retain that's missing a release.

If you click on the arrow next to the memory address of the object in Instruments, you should be able to see everywhere that your object was retained and released. You'll have look through them and identify which retain is missing a release.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文