Hi Monks!
I am coming back with questions about Safe.pm and memory handling, after reviewing the following messages:
  1. 'Displaying symbol tables for debugging' - and getting the symbol2 and packages subroutines from it.
  2. 'undef Package;' (156281) - and using Symbol delete_package subroutine.
So I created a small script checking using the information gathered.
The script uses Symbol.pm and Safe.pm, and include symbol2 and packages subroutines.
All it does is execute a Perl script that uses a module (big module), and check the memory consumption.
The script:
use Safe; use Symbol qw(delete_package); use Data::Dumper; use strict; my $rc = 0; my $namespace = "SPACE"; my $CPT = new Safe($namespace); $CPT->deny_only(); my $file = shift; print "DEBUG - before rdo-\n"; system ("ps auxww|grep safe|grep -v grep"); print "-"x40,"\n"; <>; if (-f $file) { $CPT->rdo($file); } else { print "File \"$file\" does not exists !\n"; $rc = 1; } print "DEBUG - after rdo-\n"; print $@ if (defined $@); print "Printing \%SPACE::\n"; print Dumper \%SPACE::; print "Printing \%SPACE::INC\n"; print Dumper \%SPACE::INC; print "\nOutput from space_packages\n"; space_packages(); print "\nOutput from packages\n"; packages(); print "\nOutput from symbols2\n"; symbols2("SPACE"); system ("ps auxww|grep safe|grep -v grep"); print "-"x40,"\n"; <>; delete_package($namespace); print "DEBUG - after clearing namespace-\n"; print "Printing \%SPACE::\n"; print Dumper \%SPACE::; print "Printing \%SPACE::INC\n"; print Dumper \%SPACE::INC; print "\nOutput from space_packages\n"; space_packages(); print "\nOutput from packages\n"; packages(); print "\nOutput from symbols2\n"; symbols2("SPACE"); system ("ps auxww|grep safe|grep -v grep"); print "-"x40,"\n"; <>; sub space_packages { print "Packages: ", join(" ", grep /::$/, keys %SPACE::), "\n"; print " INC: ", join(" ", sort keys %SPACE::INC), "\n"; } sub packages { print "Packages: ", join(" ", grep /::$/, keys %::), "\n"; print " INC: ", join(" ", sort keys %INC), "\n"; } sub symbols2 { my $pkg = $_[0] || ''; no strict 'refs'; print "Symbols in ${pkg}::\n"; my $hash = *{$pkg.'::'}{HASH}; for (sort grep {!/::$|^_</} keys %$hash) { my $sym = $_; my $glob = $hash->{$_}; $sym =~ s/[[:cntrl:]]/'^' . chr(ord($&) + ord('@'))/ge; print " $sym (", *{$glob}{PACKAGE}, '::', *{$glob}{NAME}, "): "; if (defined $$_) { print "SCALAR='$$glob' "; }; for my $THING (qw(ARRAY HASH CODE IO)) { my $ref = *{$glob}{$THING}; if (defined $ref) { print "$THING=$ref "; } } print "\n"; } }
The output (executed on Linux RH 7.3 with Perl 5.6.1):
[root@gili /tmp]# perl safe.pl /tmp/safe2.pl DEBUG - before rdo- root 31983 0.0 1.6 3504 2068 pts/0 S 06:26 0:00 perl sa +fe.pl /tmp/safe2.pl ---------------------------------------- DEBUG - loading module momo- test DEBUG - after rdo- Printing %SPACE:: $VAR1 = { 'INC' => *SPACE::INC, '_' => *::_, 'a' => *SPACE::a, '_</tmp/safe2.pl' => *{'SPACE::_</tmp/safe2.pl'}, '__ANON__' => *SPACE::__ANON__, 'test' => *SPACE::test, 'momo::' => *{'SPACE::momo::'}, '_<momo.pm' => *{'SPACE::_<momo.pm'}, 'BEGIN' => *SPACE::BEGIN, 'main::' => *{'SPACE::main::'} }; Printing %SPACE::INC $VAR1 = { 'momo.pm' => 'momo.pm', '/tmp/safe2.pl' => '/tmp/safe2.pl' }; Output from space_packages Packages: momo:: main:: INC: /tmp/safe2.pl momo.pm Output from packages Packages: SPACE:: Opcode:: DB:: Data:: DynaLoader:: Exporter:: warning +s:: Symbol:: strict:: XSLoader:: attributes:: UNIVERSAL:: overload:: +<none>:: Safe:: subs:: IO:: Carp:: CORE:: main:: INC: Carp.pm Data/Dumper.pm Exporter.pm Exporter/Heavy.pm Opcode.pm +Safe.pm Symbol.pm XSLoader.pm overload.pm strict.pm subs.pm warnings. +pm warnings/register.pm Output from symbols2 Symbols in SPACE:: BEGIN (SPACE::BEGIN): INC (SPACE::INC): HASH=HASH(0x81945d8) _ (SPACE::_): SCALAR='_' ARRAY=ARRAY(0x819e1c8) __ANON__ (SPACE::__ANON__): a (SPACE::a): test (SPACE::test): CODE=CODE(0x819b320) root 31983 13.0 2.4 4500 3068 pts/0 S 06:26 0:00 perl sa +fe.pl /tmp/safe2.pl ---------------------------------------- DEBUG - after clearing namespace- Printing %SPACE:: $VAR1 = {}; Printing %SPACE::INC $VAR1 = {}; Output from space_packages Packages: INC: Output from packages Packages: Opcode:: DB:: Data:: DynaLoader:: Exporter:: warnings:: Symb +ol:: strict:: XSLoader:: attributes:: UNIVERSAL:: overload:: <none>:: + Safe:: subs:: IO:: Carp:: CORE:: main:: INC: Carp.pm Data/Dumper.pm Exporter.pm Exporter/Heavy.pm Opcode.pm +Safe.pm Symbol.pm XSLoader.pm overload.pm strict.pm subs.pm warnings. +pm warnings/register.pm Output from symbols2 Symbols in SPACE:: root 31983 0.8 2.4 4500 3068 pts/0 S 06:26 0:00 perl sa +fe.pl /tmp/safe2.pl ----------------------------------------
What can we see here ?
Any suggestions, except "fork" ?

Thanks,
shushu

In reply to Safe.pm and memory problems - continue... by shushu
in thread Safe.pm and memory problems by shushu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.