Hi Monks !
I am using the modules Safe and Safe::Hole in order to execute code I am getting from external resources.
The same Perl code is going in a loop over a list of files, execute each of them, and this way check it plus minus.
As long as the code being executed is straight Perl script there is no problem, but this is the behavior when the script uses external modules -
- In case I use a different name space for every script executed - then every module used is loaded to the memory, and even after I finish the use of the module and undef the Safe object being used - it seems as though the module is not removed from the memory. This cause kind of memory "leak", since when executing a long list of modules the Perl process memory consumption is getting bigger and bigger.
- In case I use the same name space for all of the scripts executed - then every module use is loaded to the memory once as well, and even undefing the Safe compartement make no different. The main problem here is that in some cases the script needs the module to be loaded again (due to BEGIN code, for example), and that if several scripts uses different modules but by the same package name the script will actually will use a wrong package (the @INC for every script is created in the execution time and defined temporarily to create higher separation. This is why it might be the same package name with a different file).
- In case I try harder, use the same name space but undef the name space %INC variable between every script - it solves the loading of modules so the modules used are being loaded to the memory every time, bt it cause a memory problem as well - it seems that although the %INC is cleaned Perl still keeps the old loaded module copy in the memory and does not clean it until the end of the whole process.
The bottom line is -
I need to find a way to clean every piece of memory used by a former executed script in the Safe compartement in order to execute the script after it. It looks as though I will need to clean the name space itself and not the Safe object, and any new name spaces created while the script is being executed.
Since Perl's garbage collector, as far as I know, is being executed automatically without any way to force it, it seems I need to find a way to know what "data" Perl has in his memory a in order to "undef" it one by one.
Questions are -
- Is therer any way to force Perl to "garbage collect" something ?
- Is there a way to know what variables exists in a specific name space ?
- Is there a way to find what modules were loaded, and remove them from the memmory ? (cleanning the %INC is not enough)
I don't see any specific reason to send any code, but if it is necessary I will gladly do it.
Thanks all,
shushu
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.