Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

When it comes to perl, I am mostly clueless. I have defined a class. I define an AUTOLOAD function for it. When I call a non-existent method on an object instance of the class, the calling script eats up nearly all of the memory and my machine nearly freezes. The class uses DBI. Could that have something to do with this. How can I find out what is causing this memory problem? Here is a section of the code
use DBI; sub AUTOLOAD { my $self = shift; our $AUTOLOAD; print "Attempt to call $AUTOLOAD failed.\n"; exit(1); }

Replies are listed 'Best First'.
Re: Memory issues with AUTOLOAD
by jethro (Monsignor) on Feb 18, 2011 at 10:15 UTC

    I put your snippet in a class and called a non-existant method in that class. No problem. The only thing that happened was that when the script exited (in your AUTOLOAD subroutine), it tried to call the special DESTROY subroutine which triggered AUTOLOAD again. This happened only twice. Maybe you have a different perl version where AUTOLOAD gets triggered endlessly, but then you would have seen endless rows of "Attempt to call ...::DESTROY failed." on your screen. Nevertheless try adding

    sub DESTROY {}

    If that isn't the reason, you should have posted the part of your script with the bug in it ;-)

    By the way, if you try to create a minimal script that exhibits your bug you automatically isolate the bug so that you might even find it yourself.

      Thanks for the time you took to help me. Let me look at bit more into my code to see what I am doing wrong.
Re: Memory issues with AUTOLOAD (debug)
by tye (Sage) on Feb 18, 2011 at 19:38 UTC

    Sounds like infinite recursion (though Perl usually complains once it recurses 99 levels deep).

    I'd just run under "perl -d" and try "s $obj->noSuchMethodName()" and then you can see what gets called from there. You can also configure the debugger to just 'trace' what is getting called if you'd rather drudge through a lot of text rather than drudge though figuring out how to use the Perl debugger.

    BTW, a quick glance at perldebug lead me to try a google search for AutoTrace "PERLDB_OPTS" which turns up some examples of getting an execution trace.

    - tye        

Re: Memory issues with AUTOLOAD
by Anonymous Monk on Feb 18, 2011 at 05:02 UTC
    What class?