UIViewController retain count problem

前端 未结 4 1249
我寻月下人不归
我寻月下人不归 2021-01-25 16:11

I am creating a new UIViewController with the below code

GameViewController *temp = [[GameViewController alloc] initWithNibName:@\"GameViewController\" bundle:ni         


        
相关标签:
4条回答
  • 2021-01-25 16:39

    In GameViewController have you released your background music as

    - (void)viewDidLoad{
       //Other nils
       self.backgroundMusic = nil;
    }
    - (void)dealloc{
        //Other releases
        [backgroundMusic release];
        [super dealloc];
    }
    
    0 讨论(0)
  • 2021-01-25 16:42

    Never use retainCount, it does not work the way you think it does.

    If you need to see where retains, releases and autoreleases occur for an object use instruments:

    Run in instruments, in Allocations set "Record reference counts" on on (you have to stop recording to set the option). Cause the picker to run, stop recording, search for there ivar (datePickerView), drill down and you will be able to see where all retains, releases and autoreleases occurred.

    Example screenshot

    0 讨论(0)
  • 2021-01-25 16:48

    I advise you never using retainCount because it usually gives false information about the actual retaincount of your object!!!!

    Just follow the appropiate memory management practices!!!! It's very simple really, just follow the NARC principle, release only the objects that have these words: New Alloc Retain Copy. NARC! :)

    I strongly advise you using the memory leaks tool from instruments that tells you which objects were not released and which objects where released and you are trying to access.

    0 讨论(0)
  • 2021-01-25 16:54

    "You should never use retainCount". Here is a very good description, why to not: stackoverflow

    0 讨论(0)
提交回复
热议问题