Solved

how much memory is used by certain variable?

Posted on 1998-09-02
4
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Six Sigma Control Plans

705 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