Professional Web Applications Themes

Memory ysis / Leak Detection - Mac Programming

Hi, I have just acquired a mac (10.3) and need a little help with orientation using the developer tools. I am coming from a mostly linux programming background and have used tools such as valgrind in the past. I have been reading through the Memory Performance Doentation at Apple Developer Connection. What I want to do, to familiarize myself with the system, is write some basic helloworld apps, in c++, and obtain memory allocation information. For example, deliberately not delete-ing some heap allocated data. I have compiled hello.cpp (plus allocating 100 ints and not delete-ing them) with -lMallocDebug (from the ...

  1. #1

    Default Memory ysis / Leak Detection

    Hi,

    I have just acquired a mac (10.3) and need a little help with
    orientation using the developer tools. I am coming from a mostly
    linux programming background and have used tools such as valgrind in
    the past.

    I have been reading through the Memory Performance Doentation at
    Apple Developer Connection.

    What I want to do, to familiarize myself with the system, is write
    some basic helloworld apps, in c++, and obtain memory allocation
    information.

    For example, deliberately not delete-ing some heap allocated data.

    I have compiled hello.cpp (plus allocating 100 ints and not delete-ing
    them) with -lMallocDebug (from the command line - I am not using xcode
    or anything fancy) which in itself issues a large number of
    redefinition warnings from ld.

    I load up MallocDebug but on Lauching my hello program, I always
    receive the error

    Read Data
    Unable to read malloc information from (null)
    following a minute or so of spinning rainbow wheel.

    Is there anywhere I can find some sort of introduction walkthrough to
    memory debugging in OS X? Googling keeps bringing up the same few
    links.

    I am just feeling a little lost and would appreciate a little guidance
    or some basic worked examples to get me going.

    (It's probably worth noting that most of my programs are command line
    based, non-interactive ... there seems to be a general assumption that
    everything in macs is GUI - I got my mine for easy-unix-on-a-laptop
    reasons)

    Thanks very much,

    Chris
    Chris Guest

  2. #2

    Default Re: Memory ysis / Leak Detection

    In article <google.com>,
    com (Chris) wrote:
     

    You don't want to build with -lMallocDebug. If some web page told you
    to do that, can you post the URL so I can file a bug report against it?
     

    This should get you started:

    setenv MallocStackLogging 1
    ../myApp

    Then, in another terminal window,
    leaks myApp

    Hope this helps,
    Eric

    --
    Eric Albert stanford.edu
    http://rescomp.stanford.edu/~ejalbert/
    Eric Guest

  3. #3

    Default Re: Memory ysis / Leak Detection

    Eric Albert <stanford.edu> wrote in message news:<stanford.edu>... 
    >
    > You don't want to build with -lMallocDebug. If some web page told you
    > to do that, can you post the URL so I can file a bug report against it?
    >[/ref]

    http://developer.apple.com/doentation/Performance/Conceptual/ManagingMemory/index.html

    Scroll down to:
    "Simple Command-Line Programs"

    [snip]
     

    Although, using bash (as it seems to be default under 10.3)
    export MallocStackLogging 1
     

    I needed to add a call to pause() (from unistd.h) to get this working
    otherwise there was no process to examine!
     

    Thank you. Plenty be getting on with now :)
    Chris Guest

  4. #4

    Default Re: Memory ysis / Leak Detection

    [snip] 
    >
    > http://developer.apple.com/doentation/Performance/Conceptual/ManagingMemory/index.html
    >
    > Scroll down to:
    > "Simple Command-Line Programs"
    >[/ref]
    Sorry, the link seems to be a menu
    Simple Command-Line Programs is under "Examining Memory Allocation Patterns"
     
    >
    > Although, using bash (as it seems to be default under 10.3)
    > export MallocStackLogging 1[/ref]
    Correction:
    export MallocStackLogging=1
    Chris Guest

  5. #5

    Default Re: Memory ysis / Leak Detection

    In article <google.com>,
    com (Chris) wrote:
     
    > >
    > > You don't want to build with -lMallocDebug. If some web page told you
    > > to do that, can you post the URL so I can file a bug report against it?[/ref][/ref]
     

    That's only referring to programs that don't link with libSystem.
    That's not true of your application and is exceedingly unlikely to be
    true for anything you'll ever write (or anything I'll ever write :), so
    you don't have to worry about this.
     
    >
    > Although, using bash (as it seems to be default under 10.3)
    > export MallocStackLogging 1[/ref]

    Yep. I'm still using tcsh. :)
     
    >
    > I needed to add a call to pause() (from unistd.h) to get this working
    > otherwise there was no process to examine![/ref]

    Yeah...if your application exits really quickly, there's nothing around
    for MallocDebug or leaks to look at.

    -Eric

    --
    Eric Albert stanford.edu
    http://rescomp.stanford.edu/~ejalbert/
    Eric Guest

Similar Threads

  1. #39438 [NEW]: Memory leak PHP Fatal error: Out of memory
    By nikolas dot hagelstein at gmail dot com in forum PHP Bugs
    Replies: 11
    Last Post: December 1st, 08:08 PM
  2. Request: Statistical ysis - Event detection
    By Christian in forum PERL Modules
    Replies: 0
    Last Post: May 14th, 08:12 PM
  3. Memory consumption of Ruby/mod_ruby combo on Apache [memory leak]
    By David Heinemeier Hansson in forum Ruby
    Replies: 4
    Last Post: September 10th, 01:58 AM
  4. Memory ysis after Hanging
    By Mark in forum PERL Miscellaneous
    Replies: 1
    Last Post: September 4th, 07:56 PM
  5. Shareware memory leak detection utility?
    By Frank in forum UNIX Programming
    Replies: 3
    Last Post: August 13th, 03:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139