discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

debugging memory allocation


From: Marko Riedel
Subject: debugging memory allocation
Date: Wed, 29 Mar 2006 23:31:11 +0200 (CEST)

Hi folks,

I am sending a code fragment that you may find useful. It prints the
classes that have the most objects allocated. Paste into your program and
call with the number of classes you wish to see. Here is the code:



typedef struct {
    Class what;
    long count;
} debugclinf;

int cmpbycount(const void *a, const void *b)
{
    return ((debugclinf *)b)->count-((debugclinf *)a)->count;
}

void classlist(int top)
{
    Class *list = GSDebugAllocationClassList(), *ptr = list;
    int lsize = 0;
    while(*ptr!=NULL){
        lsize++;
        ptr++;
    }
    
    if(top>lsize){
        top=lsize;
    }

    debugclinf clist[lsize];
    int ind = 0; ptr = list;
    while(*ptr!=NULL){
        clist[ind].what = *ptr;
        clist[ind].count = GSDebugAllocationCount(*ptr);
        ind++;
        ptr++;
    }

    qsort(clist, lsize, sizeof(debugclinf), cmpbycount);

    for(ind=0; ind<top; ind++){
        GSPrintf(stdout, @"%12ld %@\n", 
                 clist[ind].count, 
                 NSStringFromClass(clist[ind].what));
    }
}


This has helped me find memory leaks.

Best regards,

Marko



+-------------------------------------------------------------+
| Marko Riedel, EDV Neue Arbeit gGmbH, markoriedelde@yahoo.de |
| http://www.geocities.com/markoriedelde/index.html           |
+-------------------------------------------------------------+


        

        
                
___________________________________________________________ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de




reply via email to

[Prev in Thread] Current Thread [Next in Thread]