Hacker News new | ask | show | jobs
by sqeaky 3223 days ago
You shouldn't new or malloc unless you need to. The more you allocate the more you leak.

Just stack/automatically allocate the resource and take the address with & then pass the pointer around. Because the data is automatically cleaned up you know you won't have any leaks (and certain whole other classes of bugs).

EDIT - Consider:

    int myDictLen = 0;
    int* myDictLenPtr = &myDictLen;

    /* now you can pass around the pointer myDictLenPtr 
       to functions that can used an int* and it will be
       available in this scope and automatically cleaned 
       up for you. */