Solved

how much memory is used by certain variable?

Posted on 1998-09-02
4
139 Views
Last Modified: 2010-03-05
i'm writing script, which should scan a website. it creates http request, posts it, parses returned html and stores visited urls in hash. this script use a damn lot of memory.
is there any way to find out, whether it's because of memory leak due to uncollected garbage, or it's the hash, who is using so much memory? in general, is there any way to estimate at run time the structure of memory, used by script?
0
Comment
Question by:egor_duda
  • 2
  • 2
4 Comments
 

Author Comment

by:egor_duda
ID: 1204674
Edited text of question
0
 
LVL 5

Accepted Solution

by:
b2pi earned 100 total points
ID: 1204675
One of the easiest ways to do this is to use the Storable module, and
then Store the variables, and take a look at the file sizes (note,
it's not necessary to retrieve). Take a look at

perldoc Storable

for usage details. This is a backend way of doing this.  That's
because, simply put, you don't have a memory leak, assuming, of
course, that you're using a properly compiled perl.  You may be using
copious quantities of memory due to any number of reasons, but you
don't have a leak.

Again, you're probably better off looking at your code to try and save
memory.  For instance, you might want to investigate taking memory
abusive functions and forking them off to a separate process, which
will at least return the memory they eat to the OS.

0
 

Author Comment

by:egor_duda
ID: 1204676
thanks, it works great! but, alas, it shows that "static" variables (not initialized by "new") are taking less then 1% of memory. so, it seems to me, that the only place, where i can waste memory is such part of code:

while ( ... ) {
  ...
  $h = new HTML::TreeBuilder ;
  ...
}

it creates new object on each iteration. as far, as i understand, the previous instance should be "garbage collected" at the moment of assignment new value to $h. is it so, or i should explicitly free previously allocated memory?
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1204677
It actually depends on where you're declaring h.  It won't be garbage
collected until h is either reassigned or has gone out of scope. Even
then, if anything else 'points' to it, it still won't be garbage
collected.

BTW, I've no idea offhand how you _can_ free previously allocated
memory.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now