Instruments (Leaks) and NSDateFormatter

后端 未结 3 1162
故里飘歌
故里飘歌 2021-01-13 23:57

When I run my iPhone app with Instruments Leaks and parse a bunch of NSDates using NSDateFormatter my memory goes up about 1mb and stays even though these NSDates should be

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-14 00:16

    What do you mean by discarding the NSDateFormatters? Do you release them when you are done with them?

    df = [[NSDateFormatter alloc] init]; // allocates memory
    

    Your code allocates memory but you need to call

    [df release];
    

    when you are done with them. When you allocate (or copy) object its reference count is incremented by one. When you release object (you send release message to it) the reference count goes down by one. When the reference count reaches 0 the object is deallocated.

    If you don't send it release message it will stay in memory and you have memory leak.

提交回复
热议问题