2

コードでメモリ リークを見つけようとしていますが、どこに問題があるのか​​ わかりません。私の iOS アプリケーションでは、スライド メニュー ナビゲーション パターンを使用しています。ナビゲーションコントローラーはスライドメニューで切り替えることができます。ログアウト後、すべてのコントローラの割り当てを解除し、メモリを解放する必要があります。しかし、一部のコントローラは、dealloc が呼び出され、Instruments の参照カウントが正常に見えるにもかかわらず、ログアウトした後もメモリに残ります。

設定ViewController

#   Category    Event Type  RefCt   Responsible Library Responsible Caller
0   SettingsViewController  Malloc  1   MyApp   -[SlideViewController didSelectMenuItem:]
1   SettingsViewController  Autorelease     MyApp   -[SlideViewController didSelectMenuItem:]
2   SettingsViewController  Retain  2   UIKit   -[UIViewController _addChildViewController:performHierarchyCheck:]
3   SettingsViewController  Retain  3   UIKit   -[UINavigationController topViewController]
4   SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
5   SettingsViewController  Retain  4   UIKit   -[UINavigationController topViewController]
6   SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
7   SettingsViewController  Release 3   Foundation  __NSFireDelayedPerform
8   SettingsViewController  Release 2   Foundation  __NSFireDelayedPerform
9   SettingsViewController  Release 1   Foundation  __NSFireDelayedPerform
10  SettingsViewController  Retain  2   UIKit   -[UINavigationController topViewController]
11  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
12  SettingsViewController  Retain  3   UIKit   -[UINavigationController topViewController]
13  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
14  SettingsViewController  Retain  4   UIKit   -[UINavigationController topViewController]
15  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
16  SettingsViewController  Retain  5   UIKit   -[UINavigationController topViewController]
17  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
18  SettingsViewController  Retain  6   UIKit   -[UINavigationController topViewController]
19  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
20  SettingsViewController  Release 5   GraphicsServices    GSEventRunModal
21  SettingsViewController  Release 4   GraphicsServices    GSEventRunModal
22  SettingsViewController  Release 3   GraphicsServices    GSEventRunModal
23  SettingsViewController  Release 2   GraphicsServices    GSEventRunModal
24  SettingsViewController  Release 1   GraphicsServices    GSEventRunModal
25  SettingsViewController  Retain  2   UIKit   -[UINavigationController topViewController]
26  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
27  SettingsViewController  Retain  3   UIKit   -[UINib instantiateWithOwner:options:]
28  SettingsViewController  Retain  4   UIKit   +[UIProxyObject addMappingFromIdentifier:toObject:forCoder:]
29  SettingsViewController  Retain  5   UIKit   -[UIProxyObject initWithCoder:]
30  SettingsViewController  Retain  6   UIKit   -[UIRuntimeConnection initWithCoder:]
31  SettingsViewController  Retain  7   UIKit   -[UIRuntimeConnection initWithCoder:]
32  SettingsViewController  Retain  8   UIKit   -[UIRuntimeConnection initWithCoder:]
33  SettingsViewController  Retain  9   UIKit   -[UIRuntimeConnection initWithCoder:]
34  SettingsViewController  Retain  10  UIKit   -[UIRuntimeConnection initWithCoder:]
35  SettingsViewController  Retain  11  UIKit   -[UIRuntimeConnection initWithCoder:]
36  SettingsViewController  Retain  12  UIKit   -[UIRuntimeConnection initWithCoder:]
37  SettingsViewController  Retain  13  UIKit   -[UIRuntimeConnection initWithCoder:]
38  SettingsViewController  Retain  14  UIKit   -[UIRuntimeConnection initWithCoder:]
39  SettingsViewController  Retain  15  UIKit   -[UIRuntimeConnection initWithCoder:]
40  SettingsViewController  Retain  16  UIKit   -[UIRuntimeConnection initWithCoder:]
41  SettingsViewController  Retain  17  UIKit   -[UIRuntimeConnection initWithCoder:]
42  SettingsViewController  Retain  18  UIKit   -[UIRuntimeConnection initWithCoder:]
43  SettingsViewController  Retain  19  UIKit   -[UIRuntimeConnection initWithCoder:]
44  SettingsViewController  Retain  20  UIKit   -[UIRuntimeConnection initWithCoder:]
45  SettingsViewController  Retain  21  UIKit   UINibDecoderDecodeObjectForValue
46  SettingsViewController  Retain  22  UIKit   UINibDecoderDecodeObjectForValue
47  SettingsViewController  Release 21  UIKit   -[UINib instantiateWithOwner:options:]
48  SettingsViewController  Release 20  UIKit   +[UIProxyObject removeMappingsForCoder:]
49  SettingsViewController  Release 19  UIKit   -[UIRuntimeConnection dealloc]
50  SettingsViewController  Release 18  UIKit   -[UIRuntimeConnection dealloc]
51  SettingsViewController  Release 17  UIKit   -[UIRuntimeConnection dealloc]
52  SettingsViewController  Release 16  UIKit   -[UIRuntimeConnection dealloc]
53  SettingsViewController  Release 15  UIKit   -[UIRuntimeConnection dealloc]
54  SettingsViewController  Release 14  UIKit   -[UIRuntimeConnection dealloc]
55  SettingsViewController  Release 13  UIKit   -[UIRuntimeConnection dealloc]
56  SettingsViewController  Release 12  UIKit   -[UIRuntimeConnection dealloc]
57  SettingsViewController  Release 11  UIKit   -[UIRuntimeConnection dealloc]
58  SettingsViewController  Release 10  UIKit   -[UINibDecoder finishDecoding]
59  SettingsViewController  Release 9   UIKit   -[UIRuntimeConnection dealloc]
60  SettingsViewController  Release 8   UIKit   -[UINibDecoder finishDecoding]
61  SettingsViewController  Release 7   UIKit   -[UIRuntimeConnection dealloc]
62  SettingsViewController  Release 6   UIKit   -[UIRuntimeConnection dealloc]
63  SettingsViewController  Release 5   UIKit   -[UINibDecoder finishDecoding]
64  SettingsViewController  Release 4   UIKit   -[UIRuntimeConnection dealloc]
65  SettingsViewController  Release 3   UIKit   -[UIRuntimeConnection dealloc]
66  SettingsViewController  Release 2   UIKit   -[UIRuntimeConnection dealloc]
67  SettingsViewController  Retain  3   UIKit   -[UINavigationController topViewController]
68  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
69  SettingsViewController  Retain  4   UIKit   -[UINavigationController topViewController]
70  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
71  SettingsViewController  Retain  5   UIKit   -[UINavigationController _startTransition:fromViewController:toViewController:]
72  SettingsViewController  Release 4   UIKit   -[UINavigationController _startTransition:fromViewController:toViewController:]
73  SettingsViewController  Retain  5   UIKit   -[UINavigationController topViewController]
74  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
75  SettingsViewController  Retain  6   UIKit   -[UIResponder becomeFirstResponder]
76  SettingsViewController  Release 5   UIKit   -[UIResponder becomeFirstResponder]
77  SettingsViewController  Retain  6   UIKit   -[UINavigationController topViewController]
78  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
79  SettingsViewController  Retain  7   UIKit   -[UINavigationController topViewController]
80  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
81  SettingsViewController  Retain  8   UIKit   -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
82  SettingsViewController  Release 7   UIKit   -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
83  SettingsViewController  Retain  8   UIKit   -[UINavigationController topViewController]
84  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
85  SettingsViewController  Retain  9   UIKit   -[UINavigationController topViewController]
86  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
87  SettingsViewController  Release 8   UIKit   _wrapRunLoopWithAutoreleasePoolHandler
88  SettingsViewController  Release 7   UIKit   _wrapRunLoopWithAutoreleasePoolHandler
89  SettingsViewController  Release 6   UIKit   _wrapRunLoopWithAutoreleasePoolHandler
90  SettingsViewController  Release 5   UIKit   _wrapRunLoopWithAutoreleasePoolHandler
91  SettingsViewController  Release 4   UIKit   _wrapRunLoopWithAutoreleasePoolHandler
92  SettingsViewController  Release 3   UIKit   _wrapRunLoopWithAutoreleasePoolHandler
93  SettingsViewController  Release 2   UIKit   _wrapRunLoopWithAutoreleasePoolHandler
94  SettingsViewController  Release 1   UIKit   _wrapRunLoopWithAutoreleasePoolHandler
//controller is loaded now 
//then logout button will be pressed and the memory should be released
95  SettingsViewController  Retain  2   UIKit   -[UINavigationController topViewController]
96  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
97  SettingsViewController  Release 1   UIKit   -[UIViewController _setViewAppearState:isAnimating:]
98  SettingsViewController  Retain  2   UIKit   -[UINavigationController topViewController]
99  SettingsViewController  Autorelease     UIKit   -[UINavigationController topViewController]
100 SettingsViewController  Release 1   UIKit   -[UIViewController _setViewAppearState:isAnimating:]

このログは、最後の参照カウントが 1 であり、オブジェクトが過剰に保持されていないことを示しています。別のコントローラーは正常にリリースされます。Instruments のログは同じように見えますが、ログの最後に 2 つの追加の呼び出しがあります。

//controller is loaded now 
//then logout button will be pressed and the memory should be released    
75  SummaryViewController   Retain  2   UIKit   -[UINavigationController topViewController]
76  SummaryViewController   Autorelease     UIKit   -[UINavigationController topViewController]
77  SummaryViewController   Release 1   UIKit   -[UIViewController _setViewAppearState:isAnimating:]
78  SummaryViewController   Retain  2   UIKit   -[UINavigationController topViewController]
79  SummaryViewController   Autorelease     UIKit   -[UINavigationController topViewController]
80  SummaryViewController   Release 1   UIKit   -[UIViewController _setViewAppearState:isAnimating:]
81  SummaryViewController   Release 0   UIKit   -[UIViewController dealloc]
82  SummaryViewController   Free    0   UIKit   -[UIViewController dealloc]

デバッグは、dealloc が両方のコントローラーに対して呼び出されることを示しています。また、最初のコントローラーがメモリに残っているのに、2番目のコントローラーが適切に割り当て解除される理由がわかりません。

SettingsViewController の割り当て:

self.settingsNavigationController = [[[UINavigationController alloc] initWithRootViewController:[[[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil] autorelease]] autorelease];
[self.navigationControllers addObject:_settingsNavigationController];

SummaryViewController の割り当て:

self.summaryNavigationController = [[[UINavigationController alloc]
                                             initWithRootViewController:[[[SummaryViewController alloc] initWithNibName:@"SummaryViewController" bundle:nil] autorelease]] autorelease];
[self.navigationControllers addObject:_summaryNavigationController];

SlidingController の解放:

- (void)dealloc
{    
    [self.navigationControllers removeAllObjects];
    self.summaryNavigationController = nil;
    self.settingsNavigationController = nil;
    self.navigationControllers = nil;

    [super dealloc];
}

前もって感謝します。

4

0 に答える 0