Continuos Timer and ObjectAlloc?

Discussion in 'Mac Programming' started by Darkroom, Jan 6, 2009.

  1. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #1
    i think i understand memory leaks for the most part, but the icon for object allocations in Instruments is equally as forbidding and would like some help understanding a few things.

    what potential problems can occur with continuos object allocation? i have a timer that allocates and releases an object every second... the object is a string that changes... an actual timer... i've noticed in the instruments window, under "Overall Bytes" and "#Overall" that the top listed categories continuously rise when my timer is running... is that ok/normal?

    what if someone left this timer of mine on for a month and the number kept rising and rising?
     

    Attached Files:

  2. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #2
    Overall is fine. That's "all the bytes that have ever been allocated". Net bytes is the number of allocated bytes that haven't been deallocated.
     
  3. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #3
    ok... so if i've allocating memory and then releasing it once per second, that's fine? i mean, i think because the program has to allocate a new memory block every second then it's maybe using more resources than it has to? i don't know... i think i've been reading too many really old books about the dangers of hogging resources when today's PCs are super computers compared to what they were 20 years ago...

    as someone who knows little about allocating memory for objects, is there something that i *shouldn't* do when it comes to memory allocation? maybe there's a common mistake for novice programmers that i should know about? i ask simply because i don't pay attention to what i'm allocating, just as long as it's released...
     
  4. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    There should be no net effect to allocating and deallocating an object, other than more oblique things like memory fragmentation, etc., but that is really not something you should be concerned with. My question would be, why not use an NSMutableString, or some other mutable object for this purpose so you don't have to alloc/release over and over again? It's not hurting anything but performance (and probably that is only altered very slightly) allocating each time, but there's probably not a need to do so.

    -Lee
     

Share This Page