gpt4 book ai didi

iphone - [super delloc] 语句之前和之后释放对象的区别?

转载 作者:太空狗 更新时间:2023-10-30 03:58:34 24 4
gpt4 key购买 nike

我想知道在释放我的[super delloc]对象之前有什么区别在释放了我的 [super delloc] 行对象之后

例如,之前..

- (void)dealloc {
[theAudioPlayer stop];

[soundFilePath release];

[theAudioPlayer release];

[super dealloc];
}

现在释放对象后..

- (void)dealloc {

[super dealloc];

[theAudioPlayer stop];

[soundFilePath release];

[theAudioPlayer release];
}

当我使用第一种情况时,我首先将我的 viewController 导航到第 1 个到第 2 个 viewController 类,然后再次回到第 2 个到第 1 个,然后它会在控制台后给我一些错误。

#0  0x02d29c93 in objc_msgSend ()
#1 0x0628ae60 in ?? ()
#2 0x02b24814 in __CFURLDeallocate ()
#3 0x02b23ed0 in _CFRelease ()
#4 0x0012af48 in -[NSURL release] ()
#5 0x02795827 in -[AVAudioPlayer dealloc] ()
#6 0x0000480e in -[ViewController dealloc] (self=0x6285340, _cmd=0x2c0a934) at /Users/ajm/Desktop/DetectiveJone/Classes/ViewController.m:209
#7 0x02d23e9d in objc_setProperty ()
#8 0x0039f7b3 in -[UINavigationController setDisappearingViewController:] ()
#9 0x0039ce91 in -[UINavigationController _clearLastOperation] ()
#10 0x0039d732 in -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] ()
#11 0x0054d25f in -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] ()
#12 0x0054e39e in -[UINavigationTransitionView _navigationTransitionDidStop] ()
#13 0x00325d54 in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] ()
#14 0x00325be6 in -[UIViewAnimationState animationDidStop:finished:] ()
#15 0x048a1933 in run_animation_callbacks ()
#16 0x048a17da in CA::timer_callback ()
#17 0x02b497dc in CFRunLoopRunSpecific ()
#18 0x02b488a8 in CFRunLoopRunInMode ()
#19 0x0356989d in GSEventRunModal ()
#20 0x03569962 in GSEventRun ()
#21 0x00307372 in UIApplicationMain ()
#22 0x00002018 in main (argc=1, argv=0xbffff050) at /Users/ajm/Desktop/DetectiveJone/main.m:14
(gdb)

最佳答案

第二种方式是绝对错误的。 NSObject 的 dealloc 从字面上解除分配对象,并且 [super dealloc] 不可避免地达到 NSObject 对任何正确编写的 Cocoa 类的实现。这意味着不再为执行dealloc 方法的对象分配内存,并访问曾经对象实例变量的内存——甚至只是发送它们release — 是未定义的行为。

因此,[super dealloc] 应该总是出现在方法的末尾。该行执行后,您无法做任何有意义的事情。

关于iphone - [super delloc] 语句之前和之后释放对象的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3985183/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com