Solved

how much memory is used by certain variable?

Posted on 1998-09-02
4
145 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

776 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