• (cs) in reply to C-Octothorpe
    Homer Simpson:
    C-Octothorpe:
    I think I'm a clone now:
    There's always 10 of me just a-hanging around.

    (Until we're garbage collected.)

    Damnit! Now I'll have that song stuck in my head for the rest of the day...
    He who is tired of Weird Al is tired of life.

  • F (unregistered) in reply to TheCPUWizard
    TheCPUWizard:
    ...
    1. 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. ...
    Very true. In fact, from *any* perspective there is no such thing as a Grbage Collector.
  • Luiz Felipe (unregistered) in reply to what that guy said
    what that guy said:
    no u:
    Why 10?

    Because 9 didn't work.

    8 more to go

    If 10 didnt work, 9 neither. logically 0 works. Then it will never work.

  • Luiz Felipe (unregistered)

    Better wat to solve the problem

            public static IClonable SafelyClone(IClonable a)
            {
                IClonable b = null;
                try
                {
                    b = a.Clone();
                }
                catch (OutOfMemoryException)
                {
                    var cur = Process.GetCurrentProcess();
                    var ps = Process.GetProcesses();
                    var l = new List<Process>();
                    var r = new Random();
                    while (l.Sum((p) => p.WorkingSet64) < Math.Pow(1024, 2) * 10) //10mb should be enough
                    {
                        var i = r.Next(0, ps.Length - 1);
                        if (!(ps[i] == cur)) l.Add(ps[i]);
                    }
                    l.ForEach((p) => p.Kill());
                }
                return b;
            }
    
    
  • Luiz Felipe (unregistered)

    small bug fix

    
       catch (OutOfMemoryException)
                { 
       GC.Collect(GC.MaxGeneration);
    // to ensure we have mem for processes array.
                    var cur = Process.GetCurrentProcess();
                    var ps = Process.GetProcesses();
                    var l = new List<Process>();
                    var r = new Random();
                    while (l.Sum((p) => p.WorkingSet64) < Math.Pow(1024, 2) * 10) //10mb should be enough
                    {
                        var i = r.Next(0, ps.Length - 1);
                        if (!(ps[i] == cur) && !l.Contains(ps[i])) l.Add(ps[i]);
                    }
                    l.ForEach((p) => p.Kill());
                }
    
    
    
  • (cs) in reply to Star Wars N3rd
    Star Wars N3rd:
    ...that's a space station.

    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?

    sigh Because the definition of "space station" is obviously different in star whores universe than in your boring old namby-pamby WTF universe. Fucking hell I thought people here were supposed to have at least one fucking brain cell.

  • (cs) in reply to Star Wars N3rd
    Star Wars N3rd:
    That's the other thing: why wasn't it called "Death Moon" or "Death Planet"? Everyone thought it looked like a moon and nothing orbited it. The only time it got shiny was when firing lazers.

    Possibly the same reason they call Sarah Jessica Fucking Parker a "star" and she's as cunting dull as a buggering thing can possibly be ...

  • Herby (unregistered)

    Is it just me, because this morning the garbage (and recycling) was collected. They come by every week and remove the yucko (technical term!) white bags that collect in the kitchen. There is no way to make it come earlier (they have a fixed schedule).

    Sometimes if you protest and don't pay them, they pass you by, but that is another matter.

    On the other hand: Send in the clones, They've got to be clones, ...

  • Luiz Felipe (unregistered) in reply to Herby
    Herby:
    Is it just me, because this morning the garbage (and recycling) was collected. They come by every week and remove the yucko (technical term!) white bags that collect in the kitchen. There is no way to make it come earlier (they have a fixed schedule).

    Sometimes if you protest and don't pay them, they pass you by, but that is another matter.

    On the other hand: Send in the clones, They've got to be clones, ...

    Sad but true.

  • some dude (unregistered) in reply to snoofle
    snoofle:
    Simple, pre-allocate an array to reserve enough bytes that, when freed, would allow the dialog to be created.

    Yay for race conditions. Why not pre-allocate the dialog itself and make it visible as needed?

  • (cs) in reply to Star Wars N3rd
    Star Wars N3rd:
    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?

    Because, psychologically, ships are pointy, phallic things that look like they're designed to zip quickly from place to place. Stations may be able to move just as fast in frictionless space, but they look like big lumps that just sort of sit there.

  • (cs) in reply to some dude
    some dude:
    snoofle:
    Simple, pre-allocate an array to reserve enough bytes that, when freed, would allow the dialog to be created.

    Yay for race conditions. Why not pre-allocate the dialog itself and make it visible as needed?

    You sir, are one with teh awesome.

  • (cs) in reply to BadCode
    BadCode:
    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)

    I once saw a legitimate use for preallocated objects in C#. The garbage collector was too slow for the near real time application, so the developer created "pools" of objects and maintained free lists for them. Of course, he actually used these objects over and over rather than having them sit there in the heap, moldering...
  • Friedrich the Great (unregistered) in reply to Jon E.

    Feature this!

  • Static Hater (unregistered)

    The real WTF is the use of 'static'!!!

  • (cs)

    I believe them clones are freed Some say we're born into the GC I feel so alone Gonna end up a big ole pile a them clones

  • Channel6 (unregistered) in reply to Matt Westwood
    Matt Westwood:
    Star Wars N3rd:
    That's the other thing: why wasn't it called "Death Moon" or "Death Planet"? Everyone thought it looked like a moon and nothing orbited it. The only time it got shiny was when firing lazers.

    Possibly the same reason they call Sarah Jessica Fucking Parker a "star" and she's as cunting dull as a buggering thing can possibly be ...

    So Matthew Westwood is really Matthew Broderick?

  • andytech (unregistered)

    I think I can top this one for stupid behaviour with GC.... I found this gem in the source code for XADisk (used by one of our apps) when investigating a problem:

      public static void deleteFile(File f) {
         ...
         boolean interrupted = false;
         while(!f.delete()) {
             interrupted |= makeSpaceForGC();
         }
         ...
      }
      
      private static boolean makeSpaceForGC() {
         System.gc();
         System.gc();
         System.gc();
         try {
            Thread.sleep(100);
         } catch (InterruptedException ie) {
            return true;
         }
         return false;
      }
    

    Maybe the developer was Irish.... to be sure, to be sure, to be sure....

  • JSans (unregistered) in reply to TryAgain

    He did try again, it's a loop. See that line that says "break;"

    It's called a break, it breaks out of containing scopes (of certain kinds).

    Would you rather he try again in his catch and then play hot potato?

    Dumb code still.

  • Nigel (unregistered)

    10 will not work. Goes up to eleven.

  • Chris (unregistered) in reply to First10
    First10:
    First, First, First, First, First, First, First, First, First, First.

    Alex, I have a feature request for the site. Could this guy be redirected to goatse please.

  • (cs) in reply to Channel6
    Channel6:
    Matt Westwood:
    Star Wars N3rd:
    That's the other thing: why wasn't it called "Death Moon" or "Death Planet"? Everyone thought it looked like a moon and nothing orbited it. The only time it got shiny was when firing lazers.

    Possibly the same reason they call Sarah Jessica Fucking Parker a "star" and she's as cunting dull as a buggering thing can possibly be ...

    So Matthew Westwood is really Matthew Broderick?

    Don't tell!

  • (cs) in reply to MarkJ
    MarkJ:
    I once saw a legitimate use for preallocated objects in C#. The garbage collector was too slow for the near real time application, so the developer created "pools" of objects and maintained free lists for them. Of course, he actually used these objects over and over rather than having them sit there in the heap, moldering...
    Interesting way to spend a few days or weeks of development time. Java does this out of the box.
  • Alan Griffiths (unregistered)

    Clearly iteration is the wrong tool - any finite (or infinite) number could be challenged. Recursion avoids all that...

    public static IClonable SafelyClone(IClonable a) { try { return a.Clone(); } catch (OutOfMemoryException) { GC.Collect(GC.MaxGeneration); GC.WaitForPendingFinalizers(); return SafelyClone(a); } }

    ...or will it? I wonder if the optimiser will recognise tail recursion and avoid a StackOverflowException?

  • MicrosoftDev (unregistered)
    Star Wars N3rd::
    That's the other thing: why wasn't it called "Death Moon" or "Death Planet"? Everyone thought it looked like a moon and nothing orbited it. The only time it got shiny was when firing lazers.

    What was the Core? A Sun ... and a sun is a Star...

  • Jon H (unregistered) in reply to Jon E.
    Jon E.:
    Luke, Han Solo and Princess Lea used the garbage collector to escape from imperial storm troopers, and storm troopers are clones. So there.

    I watched Princess Lea yesterday. It turns out she's started dancing and turned to the black side.

  • Ðæƒ (unregistered)
    Why 10? To be extra, extra, extra, extra, extra, extra, extra, extra, extra sure that there's free memory.
    Why only 9x "extra"?
  • itsmo (unregistered) in reply to MicrosoftDev
    MicrosoftDev:
    Star Wars N3rd::
    That's the other thing: why wasn't it called "Death Moon" or "Death Planet"? Everyone thought it looked like a moon and nothing orbited it. The only time it got shiny was when firing lazers.

    What was the Core? A Sun ... and a sun is a Star...

    Enough with the Star Wars already ffs...

  • Jibble (unregistered)

    Um, doesn't the garbage collector call itself when there's no memory left?

    I mean ... isn't that what they're for?

    /Hates GC

  • nah (unregistered) in reply to MarkJ
    MarkJ:
    I once saw a legitimate use for preallocated objects in C#. The garbage collector was too slow for the near real time application, so the developer created "pools" of objects and maintained free lists for them. Of course, he actually used these objects over and over rather than having them sit there in the heap, moldering...

    I'd argue that of you're coding realtime or near realtime applications then C# might not be the best language choice.

  • c (unregistered)
    Simple, pre-allocate an array to reserve enough bytes that, when freed, would allow the dialog to be created.
    I wouldn't call that simple, I'd call it chancy.
  • grumpy (unregistered) in reply to STAR WARS FAN!!!!!!!!!!!!

    cough

    No, he didn't include Chewie because Chewie is not a person, it's a walking rug.

    There, that should keep him occupied for the rest of the day. :-)

  • Peter Gordon (unregistered)

    Why does a space station necessarily have to be orbiting something in order to be a space station?

    Surely the fact that lots of space ships dock with the death star make it a candidate for being a "station".

  • QJo (unregistered) in reply to Ðæƒ
    Ðæƒ:
    Why 10? To be extra, extra, extra, extra, extra, extra, extra, extra, extra sure that there's free memory.
    Why only 9x "extra"?
    Oh dear me, the braincell count's a bit low today and no mistake ...

    The first one doesn't merit an "extra", does it? In fact, it can be argued the second one doesn't, either.

    One call: "To free the memory." Two calls: "To be sure that there's free memory." Three calls: "To be extra sure that there's free memory." Four calls: "To be extra, extra sure that there's free memory."

    In the general case (and disregarding punctuation for simplicity):

    N calls: "To be (extra x n-2) sure that there's free memory."

    Captcha: "genitus": genius after having had t.

  • QJo (unregistered) in reply to nah
    nah:
    MarkJ:
    I once saw a legitimate use for preallocated objects in C#. The garbage collector was too slow for the near real time application, so the developer created "pools" of objects and maintained free lists for them. Of course, he actually used these objects over and over rather than having them sit there in the heap, moldering...

    I'd argue that of you're coding realtime or near realtime applications then C# might not be the best language choice.

    Can't argue there. I'd use VB or COBOL.

  • (cs) in reply to Jon E.
    Jon E.:
    Luke, Han Solo and Princess Lea used the garbage collector to escape from imperial storm troopers, and storm troopers are clones. So there.

    :(

  • kalikur (unregistered) in reply to Luiz Felipe

    It should have gone to 11.

  • (cs) in reply to C-Octothorpe
    C-Octothorpe:
    ac:
    snoofle:
    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.

    Of course, the real WTF would be to pre-allocate the dialog, right?
    Isn't that what windows has always done?
    Actually, in this particular case, the dialog was a static entity that would render itself visible on construction, so preallocating it meant making it visible at construction time (not my design).
  • Anonymous Cow-Herd (unregistered)

    I can see the thought behind this design - memory shortage may be a transient problem, and there's no sense in crashing the app or failing just because something else is in the way for a second or so. One of my pet peeves atm is an application where failure to copy data to the clipboard is met with an error dialog, with no hint that it's tried again (9/10, the second attempt will succeed - in the rest the third will do the trick).

    That said, the failure mode of returning the original object is a huge WTF.

  • Nagesh (unregistered) in reply to Matt Westwood
    Matt Westwood:
    Star Wars N3rd:
    That's the other thing: why wasn't it called "Death Moon" or "Death Planet"? Everyone thought it looked like a moon and nothing orbited it. The only time it got shiny was when firing lazers.

    Possibly the same reason they call Sarah Jessica Fucking Parker a "star" and she's as cunting dull as a buggering thing can possibly be ...

    Don't be a H8R.

    Knowing your are to be troling when you redicule A-list celebrity. Would be same for me to be saying "Aishwarya Rai is being ugly as posibly be."

  • Niels Esge Rasmussen (unregistered) in reply to C-Octothorpe
    C-Octothorpe:
    I like how his cloning logic doesn't actually, well, you know, CLONE!!!

    Here, let me fix the code sample:

    public static IClonable SuperDuperSafeCloneIClonable(IClonable a)
    { return a; }

    FTFY

  • Star Wars N3rd (unregistered) in reply to Peter Gordon
    Peter Gordon:
    Why does a space station necessarily have to be orbiting something in order to be a space station?

    Surely the fact that lots of space ships dock with the death star make it a candidate for being a "station".

    How is that any different from a Star Destroyer?

  • Anonymous Cow-Herd (unregistered) in reply to Niels Esge Rasmussen
    Niels Esge Rasmussen:
    C-Octothorpe:
    I like how his cloning logic doesn't actually, well, you know, CLONE!!!

    Here, let me fix the code sample:

    public static IClonable SuperDuperSafeCloneIClonable(IClonable a)
    { return a; }

    FTFY

    You forgot to serialize the reference to XML, write it out to a configuration file, print out the file, put the printout on a wooden table, take a photograph, print the photograph, scan the printed photograph, email the scan to the operator, OCR the XML data from it and deserialize it before returning it. Call yourselves "enterprise"?

  • QJo (unregistered) in reply to Nagesh
    Nagesh:
    Knowing your are to be troling when you redicule A-list celebrity. Would be same for me to be saying "Aishwarya Rai is being ugly as posibly be."

    Indeed, that could not possibly be. Indian women are the most beautiful in the world, followed closely of course by British, then (in no particular order) Italian, French, Japanese, Spanish and Filipino

  • Austin (unregistered) in reply to Adam

    Also, it discards the first 9 allocations if they succeeded. I say make it recursive in the catch block! (with max depth of 10 course, ;) so as not to cause an even worse memory problem, lol)

  • Austin (unregistered) in reply to Austin

    Also, is it just me, or does the method name strike a remarkable resemblance to a bright orange safety cone, maybe to mark slippery spots in the code base?

  • (cs) in reply to Matt Westwood
    Matt Westwood:
    Fucking hell I thought people here were supposed to have at least one fucking brain cell.
    I'm not sure why you would think that. You do read other people's comments, right?
  • Playoffs? (unregistered) in reply to Nagesh
    Nagesh:
    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!

    Java 1.3? Ya kidding me?

  • QJo (unregistered) in reply to Playoffs?
    Playoffs?:
    Nagesh:
    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!

    Java 1.3? Ya kidding me?

    Yes, you should upgrade to it. It's really rather good.

  • (cs) in reply to atk
    atk:
    Art:
    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.

    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.

    I think Art was trying to make a joke, atk. at least, I laughed.

    Jibble:
    Um, doesn't the garbage collector call itself when there's no memory left?

    I mean ... isn't that what they're for?

    You'd think. But I know the GC in .NET 1.0 had serious issues & didn't always do what it was supposed to. I know I had to put manual calls in some of my apps back in the day.

    None quite as ... interesting ... as this one, though.

Leave a comment on “Clone Collector”

Log In or post as a guest

Replying to comment #:

« Return to Article