Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Tracing memory leak

by halfcountplus (Hermit)
on Sep 14, 2011 at 20:31 UTC ( [id://925997]=note: print w/replies, xml ) Need Help??


in reply to Tracing memory leak

Here's what I'm using to recursively check and correct reference counts before deletion:
void Reference_recursivePurge (SV *ref, char *txt) { char label[1024]; int rc; if (!SvROK(ref)) { rc = SvREFCNT(ref); if (rc > 1) { fprintf(stderr,"REFCOUNT for %s: %d\n", txt, rc); while (rc > 1) { SvREFCNT_dec(ref); rc--; } } return; } if (SvTYPE(SvRV(ref)) == SVt_PVAV) { AV *ray = (AV*)SvRV(ref); SV **cur; int i, len = av_len(ray); for (i = 0; i <= len; i++) { cur = av_fetch(ray, i, 1); sprintf(label, "%s[%d]", txt, i); Reference_recursivePurge(*cur, label); i++; } rc = SvREFCNT(ray); if (rc > 1) { fprintf(stderr,"REFCOUNT for %s: %d\n", txt, rc); while (rc > 1) { SvREFCNT_dec((SV*)ray); rc--; } } return; } if (SvTYPE(SvRV(ref)) == SVt_PVHV) { HV *hash = (HV*)SvRV(ref); SV *cur; char *key; int len; hv_iterinit(hash); while ((cur = hv_iternextsv(hash, &key, &len))) { sprintf(label, "%s->%s", txt, key); Reference_recursivePurge(cur, label); } rc = SvREFCNT(hash); if (rc > 1) { fprintf(stderr,"REFCOUNT for %s: %d\n", txt, rc); while (rc > 1) { SvREFCNT_dec((SV*)hash); rc--; } } } }
Manually decrementing the count is a temporary hack solution; the reporting provides a tidy clue, then the idea here is to isolate the problem and see if getting the structure in question free'd via decrement solves the memory use issue.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://925997]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-25 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found