Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Tracing memory leak

by halfcountplus (Hermit)
on Sep 14, 2011 at 20:31 UTC ( #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.


Comment on Re: Tracing memory leak
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2013-05-22 01:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (453 votes), past polls