Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I don't think garbage collection has anything to do with this at all.

In both cases, each sub doesn't return until its child has returned. As there is no limiting mechanism, no child ever returns! Therefore nothing is ever marked (unmarked) as free, so the garbage collector never has a chance to do anything?

Basically, you are simply recursing off the end of the stack in both programs.

If you want to test garbage collection, you need to throw some objects away, so that the gc has something to do.

One possible (and I emphasis possible, I know nothing of the internals of either) cause for some of the difference, is that Java is threadsafe. This implies a rather heavier stack usage than with non-threadsafe Perl?

In the Java version you are also concatenating string objects. Three times!

You start with the string (constant) "I am '", this is copied and concatenated with the stringified me, this is then copied to another and concatenated with the string "'!". That's 5 strings being created to print that one line. You should be using a StringBuffer to build this string. Or simply outputing the 3 bits as seperate strings. This is the most basic, and frequent mistake Java beginners make.

The Perl version will use it DWIM and intelligent compiling to build a single entity at the same point.

Like you said, a strong case of horses eating apples!


Well It's better than the Abottoire, but Yorkshire!

In reply to Re: Memory Use/Garbage Collection: Java vs Perl by BrowserUk
in thread Memory Use/Garbage Collection: Java vs Perl by c0d3cr33p

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-16 20:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found