- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
In my defence, at least I "get" the notion of passing references by value well enough to realise that it would necessitate incrementing the reference count when instantiating the functions formal parameters... if only there had actually been one, LOL!
Admin
Sorry, but that's a myth (bullshit, actually, and still very popular among JavaME coders :))!
The only case where it makes actual sense to do this is when you overwrite a reference with one to a new object, and both objects are sufficiently huge (e.g., large images) so you can expect the garbage collector to run during the second instantiation because there is not enough free memory left for the 2nd object.
In fact, you can generalize this as "discard your references to objects you don't need anymore before you instantiate new ones that might not fit into memory". Most modern JavaME phones have plenty of heap space, so it's only really relevant when it comes to images or audio.
Admin
No, it doesn't. It uses a generational collector where the young generation is collected by copying.
Thank you for playing.
Admin
I can tell you for an absolute fact that the GCJ/libjava JVM uses the Boehm GC to do mark and sweep.
Admin
Don't encourage foolishness. Setting things to null is a huge mistake in Java programming in all but a very small number of cases. The best case is you wind up with something set to null which should have been set to something which gave a more useful error when it was called erroneously later.
Admin
Sorry, but this is complete hogwash - nulling a reference and overwriting it with a new reference has the exact same effect - the reference is lost either way, and this renders the object eligible for garbage collection if there are no more references to it in the so-called "root set of references".
It is not guaranteed anyway that the first object is collected prior to the instantiation of the second one, no matter whether you overwrite its reference with null or directly with the new one.
OTOH the VM will run the gc in any case if there should not be enough space for the second object (thus collecting the first one), again no matter if you overwrote the first reference with null or with the new reference.
Admin
A swap function that works would be even better. This will not compile. I think there may be a typo, but even then, assuming it should be Object temp = ... , clone is protected. Digging a bit further still, clone may throw CloneNotSupportedException.
I'm not sure that you would need the clone for what you are trying to do, but, regardless of that, it's not a simple swap function. Perhaps you could explain how your code should be used and what makes it simpler than simply writing the swap inline.
In any case creation of a simple swap function in Java seems to have been less than simple.
Admin
I have to echo what some other users have said here:
I feel much more knowledgable about Java after reading some of the woefully-off-target stabs in the dark being made by C programmers.
As-written, is it pointless code? Yes.
But some folks are trying a bit too hard to find more than that.
Admin
It has not the same effect.
Try this with: -Xms24M -Xmx26M
If you do not null the reference, you will get a 'java.lang.OutOfMemoryError: Java heap space' exception. That is because the JVM allocates memory first and then replace the reference.
Captcha: esse, ich esse gerade nichts obwohl mein Magen knurrt !
Admin
Why the fuck did you first post something completely wrong and only after that actually find out the stuff you are talking about?
Admin
Don't the older generations use M&S though?
Admin
This is exactly the kind of sh*t you get when you insist to say that Java has call-by-reference semantics, while in fact it's strictly call-by-value in a local JVM.
There is subtle but important difference between passing a pointer by value (what Java does) or passing a variable by reference (which Java doesn't).
Admin
I hate java. My teacher used to say stupid stuff as examples and give us some code to copy, then piss off out the class until it was 3 mins from ending. By which time only one person in the class had managed to get it to work and he'd used a totally different method (some smug guy that already knew how to code).
I could never be assed to get a book as the language just seems retarded and why do people feel the need for such long variable names?
Admin
TRWTF here is the astounding amount of ignorance in the comments. I estimate that over 9 of 10 comments contain misleading, misguided or just plain incorrect information.
Even better are the ones that take on a condescending tone after stating something completely incorrect as fact.
Seriously, if you're not 100% sure about what you're going to say, keep your mouth shut. Especially if you're going to open it to rag on some other ignorant mutt.
Admin
This will at least throw compiler warning, but it is probably asking too much for someone to read those.
Admin
Sorry you are wrong, the method call is static so it will not create a new Destruction object every time, the second part of your answer is correct ;-)
Admin
s/(Irish)/dancing \1/