Need a tool to find memory leaks

Discussion in 'iOS Programming' started by Pulkit, Oct 15, 2008.

  1. Pulkit macrumors newbie

    Joined:
    Aug 27, 2008
    #1
    Friends,

    I need a tool which can help me to find memory leaks, bad memory allocations, allocation and deallocations problems in my application.

    Like MemCheck we have on Windows.

    Thanks,
    Pulkit
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    As per usual it's all covered in the documentation (and clearly mentioned and demonstrated in the getting started videos that all developers should have watched).

    Instruments
     
  3. dipaliP macrumors newbie

    Joined:
    Oct 6, 2008
  4. ace2600 macrumors member

    Joined:
    Mar 16, 2008
    Location:
    Austin, Texas
    #4
    I was/am planning on making a full post about this because I find it incredibly useful: Clang Static Analyzer.

    It's a tool utilizing LLVM/Clang which automatically finds memory leaks and other possible bugs with your code. It generates a nice HTML report for where the error occurs and how it got there.

    I have found sticking to a coding standard is the single best way to prevent memory leaks. For example, always autorelease or always do the init, set, release jig, etc. However, tools like the static analyzer may find bugs you were unaware of.

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

    quick tutorial on setting up for iPhone development:
    http://www.rhonabwy.com/wp/2008/10/...clang-static-analyzer-with-an-iphone-project/
     
  5. Pulkit thread starter macrumors newbie

    Joined:
    Aug 27, 2008
    #5
    I really want to use this tool. Can you tell me detail steps to install this on my machine. I tried the steps mentioned "Seatle Bus" but that didn't work.

    I have downloaded the .taz.bz file from the Clang website now can you tell me what should I do from here?

    Please help!
     
  6. ace2600 macrumors member

    Joined:
    Mar 16, 2008
    Location:
    Austin, Texas
    #6
    Sure.
    1. Go to http://clang.llvm.org/StaticAnalysis.html
    2. Download checker-xxx.tar.bz2 in the bottom right (is currently checker-113.tar.bz2 for the October 20th build)
    3. Extract to some directory (I chose ~/Development/tools/clang)
    4. Open your project in XCode and set settings to Simulator and Debug
    5. Build and Run (this step may be optional)
    6. Quit XCode
    7. In your terminal, cd to your project directory
    8. rm -rf ./build (this step may be optional)
    9. rm -rf /tmp/scan* (this is where the HTML reports are stored, this step may be optional too)
    10. run "/location/of/unzipped/file/scan-build --view xcodebuild". For example, I run "~/Development/tools/clang/scan-build --view xcodebuild". --view tells the scan-build to automatically bring up the HTML report in the browser.
     
  7. MikeBrWade macrumors member

    Joined:
    Oct 21, 2008
    #7
    Attach some instruments in the IDE the leak detector is "okay", but if you know how to read a stack and trace signals the object allocated one is the best, I tend to keep that one and the utilization ones open during my "testing" phases of development.

    Be wary of leaks they will get you if you code sloppy or even because of some of apple's own mistakes *cough*UIWebView*cough*
     
  8. Pulkit thread starter macrumors newbie

    Joined:
    Aug 27, 2008
    #8
    I follow these steps but I got a Build Failed message. Reason it gave to me is as follows:
    Reason : gcc-4.0: installation problem, cannot exec "/Developer/usr/bin/arm-apple-darwin9-gcc-4.0.1": No such file or directory.

    Any Ideas?
     
  9. ace2600 macrumors member

    Joined:
    Mar 16, 2008
    Location:
    Austin, Texas
    #9
    I had that until I switched the XCode project to Simulator instead of Device. This error is because the analyzer does not support ARM binaries.

    Also, in Step 5, instead of Build and Run, do a Clean on the target and do NOT Build and Run.
     
  10. Pulkit thread starter macrumors newbie

    Joined:
    Aug 27, 2008
    #10
    And why it is giving me following error:

    "CodeSign error: no provisioning profile found with UDID...."

    Any ideas?
     

Share This Page