Stories
Slash Boxes
Comments

News for nerds, stuff that matters

C# Memory Leak Torpedoed Princeton's DARPA Chances

Posted by Zonk on Saturday November 17, @05:22AM
from the omg-a-tumbleweed dept.
nil0lab writes "In a case of 20/20 hindsight, Princeton DARPA Grand Challenge team member Bryan Cattle reflects on how their code failed to forget obstacles it had passed. It was written in Microsoft's C#, which isn't supposed to let you have memory leaks. 'We kept noticing that the computer would begin to bog down after extended periods of driving. This problem was pernicious because it only showed up after 40 minutes to an hour of driving around and collecting obstacles. The computer performance would just gradually slow down until the car just simply stopped responding, usually with the gas pedal down, and would just drive off into the bush until we pulled the plug. We looked through the code on paper, literally line by line, and just couldn't for the life of us imagine what the problem was.'"

Related Stories

Display Options Threshold:
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
(1) | 2
  • I'll show you mine if you.. (Score:4, Funny)

    by king-manic (409855) on Saturday November 17, @05:25AM (#21388563)
    (http://www.legalresourcecentre.ca/)
    I'll show you my perpetual motion machines if you show me your perfect autonomous garbage collector. You go first.
    • Re:I'll show you mine if you.. (Score:5, Insightful)

      by El Lobo (994537) on Saturday November 17, @06:03AM (#21388699)
      The problem was not the garbage collector if you read TFA. The articule is just a shameless plug, some ad spam for some very obscure profile.

      This just tells us once again that our wonderful editors on /. don't even try to understand what's behind an article, but they just find some sensationalistic title (the more AntiMS, the better) and done. This results in more comments of the type... "See, M$ id teh SuCkS", or "thanks god for my Linuzzz."..., so they got more profit for their /. ads (oh, the irony often MS ads, BTW).

      Yellow press..... yes, I know, /. is not supposed to have any credibility like any other parasite news sites, but anyway....

    • Re:I'll show you mine if you.. by phillips321 (Score:1) Saturday November 17, @07:37AM
    • Re:I'll show you mine if you.. (Score:5, Informative)

      by Anonymous Coward on Saturday November 17, @07:55AM (#21389121)
      It's not the garbage collector's fault. If an object is still in use, it can't be collected and destroyed. Managed memory only prevents the kind of memory leak where the programmer "loses" all references to the memory and thus never frees it. It also prevents the kind of bug where memory which is still in use is freed. Programs usually crash when that happens (either the OS terminates them due to a memory protection violation or they overwrite their own data and crash later on). That is also what would likely have happened in this case if it weren't for managed memory, because obviously the programmers mistakenly thought that these objects were no longer in use, so they would have freed them when they were still handling events.
    • Re:I'll show you mine if you.. by Anonymous Coward (Score:3) Saturday November 17, @07:56AM
    • by Dr. Cody (554864) on Saturday November 17, @08:56AM (#21389379)
      A funny thing happened with during my co-op this summer:

      I was working at a coal-fired power plant which needed a new pollution control device before 2010. There, I would dig through the literature, and try to find suitable products and operating conditions for this device. Anyway, this involved a lot of meetings, conference calls, and business lunches with the suppliers in question.

      Then there was Joe.

      Joe was our Alstom sales rep: portly, humorless, slow to speak and slower to understand. He was also a devote Utahnian.

      Well, one day, we were killing time while waiting on a conference call, my supervisor left the room, and we started talking about universities. Then he dropped the bomb:

      "In my Senior year, I worked on developing perpetual motion machines."

      My supervisor then reentered the room, and we got back to work. I felt like I'd just seen a dancing frog.
    • Re:I'll show you mine if you.. by astrosmash (Score:3) Saturday November 17, @09:20AM
      • Re:I'll show you mine if you.. (Score:5, Informative)

        by fitten (521191) on Saturday November 17, @10:57AM (#21390189)
        There's also the issue where you need to explicitly remove your event listeners when you no longer need the object. The listener keeps a reference to the object (via the interface) so even if it goes out of scope or what-have-you, YOU may think you don't have any references to the object but it implicitly does, through the listener you handed to the system. So... if you're using event listeners, make sure you explicitly remove them in your object's destructure... or else you'll end up with a memory 'leak'.
        • Re:I'll show you mine if you.. (Score:5, Interesting)

          by TheRaven64 (641858) on Saturday November 17, @11:02AM (#21390227)
          (http://theravensnest.org/ | Last Journal: Tuesday November 27, @07:07AM)
          Mod parent up, and anyone doing any AJAX coding pay attention. This is one of the easiest bugs to create in JavaScript. JS is a very powerful language with a Self-like object model which a lot of people seem to treat as a basic variant. This means that they create closures when they intend to pass function pointers and end up creating large numbers of object references (the closure itself is an object and it retains a lot of references) preventing the garbage collector from doing anything useful. This is particularly common with AJAX where closures are often used for handling asynchronous events (which would be a gorgeous coding style if the syntax were slightly less ugly).
        • Re:I'll show you mine if you.. by E-Prime (Score:1) Saturday November 17, @06:02PM
        • Re:I'll show you mine if you.. by I'm Don Giovanni (Score:2) Saturday November 17, @08:02PM
        • 1 reply beneath your current threshold.
      • 1 reply beneath your current threshold.
    • Re:I'll show you mine if you.. by hey! (Score:2) Saturday November 17, @12:13PM
    • This couldn't be true by running mate (Score:1) Saturday November 17, @09:06PM
    • Re:I'll show you mine if you.. by hoppo (Score:2) Saturday November 17, @11:13AM
    • Re:I'll show you mine if you.. by budgenator (Score:2) Saturday November 17, @01:55PM
    • Re:I'll show you mine if you.. by LordEd (Score:2) Saturday November 17, @02:24PM
    • 1 reply beneath your current threshold.
  • Well, there's your problem! (Score:5, Funny)

    by feepness (543479) on Saturday November 17, @05:27AM (#21388573)
    (http://www.fodors.org/)

    We looked through the code on paper, literally line by line, and just couldn't for the life of us imagine what the problem was.
    This may be the least effective method of debugging in existence.
  • Slashvertisement (Score:5, Informative)

    by shartte (1002567) on Saturday November 17, @05:28AM (#21388579)
    The linked "article" is just a "sponsored review" for a C# profiler...
    • Re:Slashvertisement (Score:5, Interesting)

      The sad thing is that Microsoft offers a perfectly servicable profiler for free that can be used on any C# application and is better than most commercial native Win32 profilers...
    • Re:Slashvertisement (Score:5, Insightful)

      Yeah, it's kind of bizarre. I'm not part of the crowd that actually believes the /. people get anything for posting these articles.

      But I do believe that articles written by companies pretending to be written by end-users are not terribly useful and probably shouldn't end up on /.

      I mean, the article clearly states at the top "By Red Gate Software.".

      So where did the "Bryan Cattle reflects on ..." credit come from? Some random line towards the bottom of what appears a highly edited blurb?

      Seriously.

      "One of our team members downloaded the 14-day trial of ANTS Profiler"

      "To our amazement, it was only minutes before we realized that our list of detected obstacles was never getting garbage collected"

      "If Only We Had Used It Earlier..."

      ANTS Profiler helped us fix a problem in minutes that would have taken us weeks to track down. If only we'd thought of it before the competition, we would most likely have finished the entire race and had a chance at the top prize money.

      All this stuff sounds either very naive or very marketing. You choose.
      • Re:Slashvertisement by Florian Weimer (Score:2) Saturday November 17, @06:19AM
        • Re:Slashvertisement by WeirdJohn (Score:3) Saturday November 17, @06:34AM
          • Re:Slashvertisement (Score:5, Insightful)

            by jmccay (70985) <{moc.loa} {ta} {yaccmeoj}> on Saturday November 17, @07:13AM (#21388969)
            (Last Journal: Thursday July 28 2005, @08:28PM)
            I think this is just poor code debugging skills. The new garbage collected languages (C# and Java) seem to be creating coders that don't know the basics of debugging. If this was C++, the bug would have shown up when an event occurred and the code called a deleted object. It would have been harder to track down. In any case, I would have added code to analyze the state of the stack and it's objects since it only occurred after the program/car had been running for a while. Also, had it not occurred to them to increase the number of obstacles beyond the "controlled" environment? You can easily write test code to to add a lot of objects into the stack without the use of the car.

            Our cars used an asynchronous event-based code stack written from scratch by us.
            They wrote their code stack from scratch. They should have modified an existing one that was proven to work. Either way, I think this is a case of sloppy programming. I don't think it is worth mention aside from the case what the closest thing to a memory leak is that you can have. Unfortunately, that too should have come to mind from them. They ruled that out because "most of [their] code is written in garbage-collected C#". Just because a language is garbage collected, it doesn't mean you can just ignore the issues. All reference to the object must be removed for it to be deleted. This is definitely a case of sloppy programming. I would be embarrassed if my name were attached to this.

                  Some old Visual Basic programmer jokes come to mind when I read this article. People use to make fun of Visual Basic programmers because it was to easy to write programs in VB. They thought it would produce sloppy code with errors, and other similar things. To some extent, it appears that same case could be made for C#, and to a lesser extent Java. In the end this is simply a case of not stress testing their event stack.
            • Re:Slashvertisement by Etrigoth (Score:1) Saturday November 17, @07:23AM
            • Re:Slashvertisement (Score:5, Insightful)

              by h4rm0ny (722443) <h4rm0ny&tarddell,net> on Saturday November 17, @07:58AM (#21389133)
              (Last Journal: Tuesday December 02 2003, @06:03AM)

              Agreed. I was a good VB programmer. But my VB experience was an eight-month interval between C++ jobs. I've knocked out minor MS Office applications when needed since then, but that's it. I'm sorry to say that most of the VB programmers I've worked with were very poor engineers. Admittedly I've not worked in VB for wealthy companies whilst I have in C++, so that colours things somewhat. I don't doubt that there are some good VB programmers out there. But in the cases of most of those I worked with, I could very clearly see how VB led them to be poor engineers. The amount of shortcuts and wizards and instances where they would start their program by dragging a form object onto the design panel and dumping form objects onto it was obviously a leading reason for their poor skills. VB *led* them to take this approach. It works for small Excel apps, barely for database front-ends and not well at all for large projects.

              As is common with the lower end of Microsoft products, the selling point is that they make it very easy to do what they think you want to do. The ability of VB to knock out an interactive form with near-zero knowledge of programming has encouraged a lot of colleges to sell people the idea that a ten-week course of dragging and dropping text box objects is programming whilst a lot of cheap or ignorant employers have taken the graduates at their word and plunged them in over their heads.

              VB is a poor language in many ways and not, imo, suited to a large or sophisticated project. But you can find good VB programmers (was one). It's just that it encourages bad ones.

              Oh, the summary is also wrong. C# hasn't started springing leaks. The programmers missed a reference to objects that they were creating and the garbage collection therefore never triggered to unallocate the memory. I don't doubt it's not easy to automate a vehicle to drive any even 9 miles, but this could have been detected with more thorough debugging. At any rate, the article submitter and overseeing editor should be ashamed of twisting this into an anti-Microsoft jab. I'm a Linux programmer. I can tell you that Linux can compete happily without sinking to the level of lies and misinformation.
            • Re:Slashvertisement by samkass (Score:3) Saturday November 17, @10:07AM
            • Re:Slashvertisement by TargetBoy (Score:3) Saturday November 17, @11:43AM
            • Re:Slashvertisement by WeirdJohn (Score:1) Saturday November 17, @02:20PM
            • 2 replies beneath your current threshold.
          • Reboot every so often? (sign of failed process) by rhyre417 (Score:1) Saturday November 17, @10:27AM
          • Erm, they're STUDENTS... by mad.frog (Score:2) Saturday November 17, @03:12PM
          • Re:Slashvertisement by MMC Monster (Score:2) Saturday November 17, @09:22PM
      • Re:Slashvertisement by GrievousMistake (Score:1) Saturday November 17, @06:56AM
      • Don't Slashvertise. Ever. (Score:5, Insightful)

        by spun (1352) <loverevolutionar ... m ['o.c' in gap]> on Saturday November 17, @11:14AM (#21390299)
        (Last Journal: Tuesday August 07, @01:18PM)
        Come on. Really. What kind of idiot marketer sends in stories like this to Slashdot? We know what happens. First, you get derided mercilessly for trying to sway us with your ridiculously transparent attempt at marketing. Then, the real experts come out and poke holes in everything you've said. Then everyone else chimes in with better (and often free) alternatives. You and your company end up looking like buffoons, and your product ends up looking like utter garbage.

        You may think you're pulling one over on the editors, and maybe you are. But you aren't pulling one over on us, and I think after all these years, the editors know this. So, just don't. Unless your product or service is absolutely bulletproof people here are more likely to shoot it full of holes than rush out and buy it.
    • Re:Slashvertisement by ydrol (Score:2) Saturday November 17, @08:53AM
    • Re:Slashvertisement (Score:4, Informative)

      by Ronin Developer (67677) on Saturday November 17, @10:39AM (#21390077)
      It might be slashvertisement, but it also speaks a painful truth that many developers seem to forget.

      The company I worked for, in the efforts to get something out the door, deployed a product to a customer site that had a similar flaw (but, not a .Net app). Every hour or so, it would simply lock up. The solution that was proposed was a script to restart the application at a specific interval rather than track down the actual bug itself and fix it. And, like the Princeton team, they underestimated the time interval when the system was put into a real production environment and more users came online.

      In my own work, I wrote NT services that HAD to run 24x7 and were not allowed to crash - especially due to memory leaks. The components we purchased and used, contrary to their marketing ploy, often had memory and resource leaks - we won't even begin to talk about the runtime library that shipped with the compiler.

      I used a variety of freely available memory managers and commercial QA tools to track down most of the "leaks" and fixed them. If I didn't have source to the component in question, I replaced them or rewrote them from scratch taking time to make sure it didn't leak. Guess what? It worked and those applications/services run 24x7 (well, until they restart server for some other reason).

      Moral of the story - if something is critical - take the time to profile your code and use QA tools to find other potential problems BEFORE you deploy.

      RD
    • Jeez, ya think? by bXTr (Score:1) Saturday November 17, @09:33PM
  • Stupid Slashdot headline (Score:5, Interesting)

    by RzUpAnmsCwrds (262647) on Saturday November 17, @05:29AM (#21388587)
    This is a stupid, stupid article headline. Of course you can have a memory leak in a managed language! Any Java programmer who's decent understands that.

    It's not C#'s fault. The team had references to the obstacle list (event handlers), which prevented garbage collection. The .NET CLR did its job, just like it was supposed to.
    • Re:Stupid Slashdot headline by dgun (Score:3) Saturday November 17, @05:46AM
      • Re:Stupid Slashdot headline (Score:5, Interesting)

        by cnettel (836611) on Saturday November 17, @06:18AM (#21388755)
        There is no explicit delete in C#. They may have added something in their framework, or they're just saying that they called delete on the collection where they thought they stored all objects. The GC isn't psychic. (It could be a good thing to ask the GC to delete an object explicitly and get an exception if it's indeed still referenced elsewhere, but that's not possible in C#, or Java for that matter.)
      • Re:Stupid Slashdot headline (Score:5, Insightful)

        by blowdart (31458) on Saturday November 17, @06:25AM (#21388789)
        (http://idunno.org/)

        I think you're getting hung up on the method name. There is no standard "delete" function that marks something as unused (dispose on the other hand sort of gets there). The article itself is unclear but I would assume that they were simply deleting the collision objects from a collection of potential hazards. Whilst that would remove the object from the collection itself it is *not* a delete. As references to the object existed elsewhere the object still exists (look ma, no null pointer exceptions) no delete happens. You cannot specifically say to the GC "We're done with this, delete it", the GC sweeps on a regular basis looking for objects with no references.

        Would you really want the GC deciding that just because an object is no longer part of a collection it's safe to unsubscribe it from events and delete it? I know I wouldn't.

        • Re:Stupid Slashdot headline (Score:4, Insightful)

          by multi io (640409) on Saturday November 17, @07:46AM (#21389081)
          You could just use weak references (does C# support that?) for all references that the event sender uses to reference its event receivers. In that case, as soon as a receiver has been removed from all those "obstacle lists" and all other objects that held references to it, the weak reference would be the only reference pointing to the receiver, which would make the receiver eligible for garbage collection.
          • Re:Stupid Slashdot headline by dohmp (Score:2) Saturday November 17, @08:51AM
          • Re:Stupid Slashdot headline (Score:5, Interesting)

            by Mr. Shiny And New (525071) on Saturday November 17, @10:52AM (#21390143)
            (http://home.primus.ca/~mr.shiny/ | Last Journal: Thursday June 28, @11:34AM)
            You might not be able to use weak references since they introduce (at least in Java) a layer of indirection. For example, an addListener method usually takes an interface of some kind of Listener, not a WeakReference (to a listener).

            Now, if you have control of the implementation of the object who accepts Listeners you can store them internally in a weak collection, which allows them to be garbage-collected. This would work but may not be what the programmer intends. Actually in a language like Java I'd hazard that usually the programmer wouldn't want that at all: consider an application that listens to UI events. As a programmer I want to be able to stick listeners wherever they are needed and leave them there permanently. If I don't need a pointer to the object, I don't want to keep it around, and thus may not have a reference to the listener EXCEPT in the event-management collection. That's the advantage of GC languages: as soon as the object which creates those events (say, a dialog box) goes away, the objects it refers to have one fewer pointer and may be eligible for GC.

            Anyway, lots of code has issues like this: we had a problem at my work where an Apache taglib was caching some compilation in a cache that would grow for ever. It was a simple code fix to solve that problem, but there was no way for us to even SEE the problem until we ran our application under load in a profiler. Fun fun fun.
        • Re:Stupid Slashdot headline by rbanffy (Score:2) Saturday November 17, @08:25AM
        • Re:Stupid Slashdot headline by dgun (Score:1) Saturday November 17, @03:21PM
        • 1 reply beneath your current threshold.
      • Re:Stupid Slashdot headline by CodeMunch (Score:2) Saturday November 17, @01:43PM
    • Re:Stupid Slashdot headline (Score:4, Insightful)

      by MathFox (686808) on Saturday November 17, @05:52AM (#21388653)
      I do think that this "object lifetime" bug is NOT a memory leak, but that does not change the effects (crash) of the system.
      What is interesting is to see that garbage collection changes one class of bugs (forgetting to explicitly deallocate memory) to another one: unintentionally keeping objects around. Princeton's "obstacle object" lifetime policy was stepped upon by a Dotnet library; Java has similar problems in its libraries. For the Princeton car software, an explicit deallocation routine (like in C/C++) would have been easy to implement.

      Problem is that both C/C++ style memory leaks and C#/Java hidden reference bugs usually remain hidden until the system crashes or trashes after some time. It makes them hard to find in the course of ordinary testing.