Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: threads and leaking scalars (Scalars leaked: 1)

by dpmott (Scribe)
on Feb 26, 2004 at 18:09 UTC ( #332064=note: print w/replies, xml ) Need Help??


in reply to threads and leaking scalars

I had this very same problem, and I finally figured it out.
If you change this line (in new()):
my ( $pkg,$config ) = @_;
To this:
my $pkg = shift; my $config = shift;
then it will work.

I suspect that there's too much magic associated with the @_ variable to let threads play nicely with it. So, my recommendation is to *not* use @_ in the same scope as you launch new threads.

Update:
Unfortunately, including other modules (say, XML::DOM) may cause this same problem, so you'd have to launch all of your threads before bringing in such modules. This might be a good use for Thread::Pool...

Replies are listed 'Best First'.
Re^2: threads and leaking scalars (Scalars leaked: 1)
by myuserid7 (Scribe) on Mar 21, 2008 at 00:37 UTC
    dpmott, If you are still here--THANK YOU! This has to be one of the nastiest perl warnings to track down. You have saved me many more days of frustration.
Re^2: threads and leaking scalars (Scalars leaked: 1)
by ikegami (Patriarch) on Mar 21, 2008 at 01:09 UTC

    So, my recommendation is to *not* use @_ in the same scope as you launch new threads.

    shift (in a sub) and shift(@_) result in exactly the same code, so you are still using @_.

    >perl -MO=Concise,x -e"sub x { shift } main::x: 5 <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->5 1 <;> nextstate(main 1 -e:1) v ->2 4 <1> shift sK/1 ->5 3 <1> rv2av[t2] sKRM/1 ->4 2 <#> gv[*_] s ->3 -e syntax OK >perl -MO=Concise,x -e"sub x { shift(@_) } main::x: 5 <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->5 1 <;> nextstate(main 1 -e:1) v ->2 4 <1> shift sK/1 ->5 3 <1> rv2av[t2] lKRM/1 ->4 2 <#> gv[*_] s ->3

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2023-09-27 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?