- 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
First, First, First, First, First, First, First, First, First, First.
Admin
Heh.
P.S. No, my comment is not spam!
Admin
First, Frist,First, Frist,First, Frist,First, Frist,First, Frist,
Admin
I did something vaguely like that a very long time ago, but not in a loop. Our system needed to slurp up pretty much all the memory our (then) modest Unix box could muster. Depending upon what you were doing, the right combination of inputs could cause enough stuff to be loaded into cache that we'd get an out of memory error.
Bigger boxes were ordered, but because of budgets, weren't going to arrive for a while.
The requirement was that when it happened, we were to pop a dialog saying it was out of memory and that the system would exit, so the user wouldn't just sit there with a hung system. But how do you get the memory for a dialog if you're out of memory?
Simple, pre-allocate an array to reserve enough bytes that, when freed, would allow the dialog to be created.
Admin
So, if it fails ten times, then you just give up and return a reference to the original object? Aargh!
Admin
Reminds me of an application I was asked to support, the original author had decided it would be easy to create 'upfront' 4096 objects of each needed type (WinForms, TextBoxes, ListBoxes, Panels, etc. etc. etc.) and store them in individual arrays, with ultra complex logic to determine which Form/control was available.
The said logic for upfront creation was 'to ensure we do not fail later on' while creating objects due to Out Of Memory conditions)
Admin
+1
Admin
It really annoys me to see code where the programmer obviously thought "OK, something might go horribly wrong here, but if it does, I'll just shrug it off and muddle on."
Instead of looping 10 times and then fail, it should have been an infinite loop with sleep calls so that the program will simply pause until the required memory is available and then proceed to complete its assigned task.
Admin
Because 9 didn't work.
Admin
Because 9 didn't work.
Admin
Because seven eight nine.
Admin
8 more to go
Admin
I like how it just returns the original after 10 tries.
"Could you clone please? please? oh, no? Well, nevermind then..."
Captcha: nisl
Admin
I agree that sleeps are better, but I do not agree about an infinite loop. If the system is unrecoverably out of memory, an infinite loop would look like a hang rather than providing opportunity to gracefully handle the failure. Graceful recovery would then require a finite number of tries. Perhaps a configurable timeout would have been useful ("after M minutes, we're really out of memory, so just give up").
And 10 may simply have been good enough to recover the application in the environments where the problem exhibited itself. Not all problems are fully understood when they're patched - sometimes a tweak here or there hides a deeper, extremely difficult to diagnose problem. And if the product does what it's supposed to do, under the conditions in which it is used, is that not good enough until the problem is better understood? Or would you prefer a production-down situation to an ugly, temporary workaround?
In such cases, it would be good to insert a comment, "Regarding the magic number 10: it just seems to work, and I don't have any better idea how to do this, right now." If the code reviewers don't have a better suggestion, and the component is not critical enough for an architect to look at, then it may well be good enough.
Admin
10 GC calls on the stack, 10 GC calls. pop on off, pray that it worked, 9 GC calls on the stack.....
Admin
Admin
Say, Can we clone? Can we clone? Memory out of control Can we clone? Can we clone? We're doing it from wall to wall Can we clone? Can we clone? Everybody try again! Can we clone? Can we clone? Everybody do it again!
SafelyClone() Is it safe to clone? Is it safe to clone?
Admin
Luke, Han Solo and Princess Lea used the garbage collector to escape from imperial storm troopers, and storm troopers are clones. So there.
Admin
Added proper commenting:
Admin
Dunno why the stupid programmer did not try again after the GC was invoked.
I mean, we probably freed up some memory, lets try again 10 times ...
Admin
+1 Classic.
Admin
Send in the clones
Admin
You forgot: C C, O O, D D, E E, S S, O O, D D
Admin
I thought the first rule of optimization is: you do not talk about optimization.
Admin
Admin
Admin
I like how his cloning logic doesn't actually, well, you know, CLONE!!!
Here, let me fix the code sample:
Admin
That's what the code does. Tries again and again until no exception is thrown. Or 10 is hit.
Admin
I've always said, the best "clone" method is one where you never know whether you actually got a clone.
Admin
Admin
He didn't forget Chewbacca. Chewbacca did not "escape" from the storm troopers. He graciously allowed them to live, by taking an alternative route back to the ship.
Nothing can kill a Wookie.
Admin
Admin
Except, y'know... having a moon land on top of them.
Admin
Fixed?
Admin
NEVER call GC.Collect from "Real" code. For any company/project/team I am involved with, that is an immediate firable effect.
Do not think you relly know what the GC is doing (unless you really are an expert). In fact from a purist perspective there is no Grbage Collector.
Hint: Temporary Objects to NOT cause issues, they prevent them. The overhead of GC is based much more of the complexity of the LIVE object graph. The frequency of GC is dependant on the total allocation rate...
So, would you rather have 1 GC that runs for 200mS, or 100 GC's that each run for 25uS?????
Admin
Admin
Can anyone come up with a reason (sane or not) for making the assignment to b on the method's first line?!
Admin
Admin
Admin
Never mind. Ekolis had already written the answer, which is far more WTF than anticipated. :)
Admin
That's one of the things that has always confused me...why did they continually refer to it as a "station?" Never in the first movie did it even orbit a planet. It was mobile, so how was it not simply a space ship?
Admin
Dr Evil: (evil laugh) Clones!
Dr Evil: (even more evil laugh) Ve must haf more clones!
Dr Evil: Arrrrrrrrgggggghhh!!!!!! Out of memory??!! Vhy must my evil plans always be foiled???!!
Admin
Admin
There's always 10 of me just a-hanging around.
(Until we're garbage collected.)
Admin
Admin
Not even the Wookie Monster?
Admin
Better to be using WekReference class for managing memory needs:
WeakRefrence http://download.oracle.com/javase/1.3/docs/api/java/lang/ref/WeakReference.html
NOT spam, askimet, m*******d!
Admin
Admin
Admin