|Problems? Is your data what you think it is?|
Re: Memory Use/Garbage Collection: Java vs Perlby BrowserUk (Pope)
|on Sep 02, 2002 at 21:24 UTC||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!