Got memory leak problem when i used NSXMLParser same as SeismicXML Example

前端 未结 3 563
说谎
说谎 2021-01-27 10:42

I have done xml parsing same as SeismicXML example. But now it gives me memory leak problem.

When i tested SeismicXML with instruments, it also give same memory leak.

相关标签:
3条回答
  • 2021-01-27 11:23

    ok,

    I am supposing you correctly installed the tool so that you can invoke it from a terminal.

    To use it:

    1) cd /your/project/path 2) scan-build -k -V xcodebuild

    if this does not work then you have not installed the tool correctly: at least you do not have your "path" correctly set.

    Here is how to set the path for c or tcsh shell , asuming you installed the tool in /opt/checker-0.160

    set mypath=(/opt/checker-0.160) set path=($mypath $path)

    3) if the command works correctly, it build your project and starts a web server on your machine. It then gives you the url where you can connect to on your machine to read the results.

    If the command is not able to start a web server, it will anyway tell you that the html files are available in a specific directory and you will be given the path. Usually this directory is to be found under /tmp.

    Simply go to this directory

    cd /path/to/results/directory

    and then

    open index.html

    You will see the full report. Best Regards.

    0 讨论(0)
  • 2021-01-27 11:25

    You may want to download, install and use the CLANG checker tool to understand why your code is leaking memory. This tool (which is already built for Leopard 10.5.x) may sometimes fail to provide the correct answer, but in my personal experience it never failed. I highly recommend it as one of your daily development tools.

    You can download it from

    http://clang.llvm.org/StaticAnalysis.html

    Usage it really simple. Take a look at

    http://clang.llvm.org/StaticAnalysisUsage.html#BasicUsage

    In practice, you simply build your Xcode project using the command

    scan-build -k -V xcodebuild

    then, you inspect the resulting output HTML files using the command that will appears as output in your terminal window. These files will give you a detailed explanation of why something is wrong in your code (not just memory leaks).

    Kind regards

    0 讨论(0)
  • 2021-01-27 11:38

    Before I initialize my NSXMLParser I set the following:

    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];
    NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:URL];
    

    This stops leaking.

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