相关疑难解决方法(0)

如何检查对象是否已释放?

我需要能够检查我是否已经在objective-c中发布了一个变量.我试过检查它是否变为null:

//Checks if buildview is null and returns respective output
if(BuildView == NULL)
    NSLog(@"Build View Value (pointer): Null");
else
    NSLog(@"Build View Value (pointer): Not Null");

//allocates memory and initalizes value
BuildView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];

//Checks if buildview is null and returns respective output again
if(BuildView == NULL)
    NSLog(@"Build View Value (pointer): Null");
else
    NSLog(@"Build View Value (pointer): Not Null");

//Releases the view
[BuildView release];

//Checks if buildview is null and returns respective output again
if(BuildView == …
Run Code Online (Sandbox Code Playgroud)

null memory-management objective-c

6
推荐指数
2
解决办法
1万
查看次数

测试对象是否已取消分配

我有一种情况偶尔我的-tableView: numberOfRowsInSection:方法要求解除分配的NSArray的计数.我希望能够测试该阵列的方式,是安全的,不会做出僵尸通话被释放.

我的代码目前看起来像:

-(NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
    if (! self.offers){
        return 0;
    }
    return [self.offers count];
}
Run Code Online (Sandbox Code Playgroud)

我只是通过调试程序逐步完成并观察它通过! self.offers测试然后残酷地崩溃[self.offers count].我打开了NSZombies,在那一行我得到了NSLog消息:

-[__NSArrayM count]: message sent to deallocated instance 0x283dc0
Run Code Online (Sandbox Code Playgroud)

所以,无论是self.offers,在这一点上,是不是零,但也没有任何在有效指出.我该如何测试呢?

编辑:感谢强烈的爱,朋友们.我已经想通了,为什么我一直在用我的内存管理的麻烦-它实际上是委托关系,挥之不去的时间比他们有用的问题.请参阅此处以获取我的问题的完整答案: 管理对视图退出时取消分配的对象的调用

iphone objective-c

4
推荐指数
1
解决办法
1万
查看次数

如何判断引用的对象是否已在objective-c中释放?

升级到iPhone OS 4.0后,应用程序切换后应用程序开始崩溃.当应用程序收到内存警告时,应用程序在同一位置崩溃.

看来,当收到内存警告时,某些对象会自动释放,然后当我们尝试使用解除分配的对象时应用程序崩溃.

是否可以测试对象是否已被释放,以便我们可以重新分配它们?

iphone objective-c multitasking didreceivememorywarning ios4

1
推荐指数
1
解决办法
3610
查看次数