Memory Leak In line of code

前端 未结 3 825
误落风尘
误落风尘 2021-01-22 12:17

My app is working fine, but when I run instrument for checking for leaks, it shows me a leak at this line of code, in purple with a 100.0% mark:

xmlParser = [[NS         


        
3条回答
  •  难免孤独
    2021-01-22 13:00

    You never release FinalString (at least not in the code you posted)

    this is held in the URL, which is held by the parser :)


    Also, have you considered what would happen if this function is called twice?

    Each time you say

    xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    

    you would leak the previous xmlParser ;)

    If you are allocating to an instance variable, you have to remember to release the previous object i.e.

    [xmlParser release];
    xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    

提交回复
热议问题