Slashdot Mirror


C# Memory Leak Torpedoed Princeton's DARPA Chances

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.'"

560 comments

  1. I'll show you mine if you.. by king-manic · · Score: 4, Funny

    I'll show you my perpetual motion machines if you show me your perfect autonomous garbage collector. You go first.

    --
    "There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy."
    1. Re:I'll show you mine if you.. by El+Lobo · · Score: 5, Insightful
      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....

      --
      It's time to realise that Abble's products are the biggest abomination these days. Just say NO to the dumb iAbble way!!
    2. Re:I'll show you mine if you.. by phillips321 · · Score: 1

      this one looks like garbage to me:
      http://www.forumpix.co.uk/uploads/1195302814.jpg

    3. Re:I'll show you mine if you.. by Anonymous Coward · · Score: 5, Informative

      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.

    4. Re:I'll show you mine if you.. by Anonymous Coward · · Score: 3, Insightful

      Sad story, but it was THEIR fault. The story title "C# Memory Leak ..." is flat out wrong.

      There is no leak in C# per se. They kept a reference to the objects, so the CLR wasn't even supposed to delete them.

      Morons shouldn't be making car software.

    5. Re:I'll show you mine if you.. by WhatAmIDoingHere · · Score: 2, Insightful

      Slashdot is a blog not a news source. I wish more people would realize that.

      --
      Not a Twitter sockpuppet... but I wish I was.
    6. Re:I'll show you mine if you.. by astrosmash · · Score: 2, Interesting

      It really has nothing to do with running out of memory. Their event dispatcher needs to notify a rapidly increasing number of listeners for each event, and eventually cannot keep up. Hence, their system slows over time and eventually stops.

      A moderately experienced programmer would recognize the problem very easily by, say, noticing that a listener method is getting called 100,000 times for each event.

      --
      ENDUT! HOCH HECH!
    7. Re:I'll show you mine if you.. by bhima · · Score: 4, Insightful

      Fuck. You are so right. This article is just some advertisement for some obscure profiler.

      However I take exception to your use of the world "Editor". Slashdot does not have Editors. They have guys who accept submissions.
      They don't read The Fucking Articles, They don't check links, The don't edit submissions...

      --
      Nothing in the world is more dangerous than sincere ignorance and conscientious stupidity.
    8. Re:I'll show you mine if you.. by GooberToo · · Score: 0, Troll

      It was written in Microsoft's C#

      Hehehehehehhehehe. Bwahahahahahhaa!

      Seriously! Any military technology written in C# should automatically be disqualified. It's not vendor neutral. The language has not been around long enough to be proven reliable (*surprise*). And MS constantly makes changes to it so it is unlikely to ever be proven reliable. This smacks of idiocy.

      All I can say is, "GOOD!" They got what they asked for. Dumb asses. Their task is hard enough without having to figure out if their technology base is working against them. With so many language choices available which squarely fall outside of my first paragraph's criticisms, this is just dumb.

      I can't tell you how many man months I've spent tracking down crashes and bugs which ultimately wind up being MS' bugs. Multiply that times the number of developers which have used MS tools and the thousands of wasted man years becomes unbearable. Either you're not doing anything worth being done of you're a shinny, new, ignorant developer which has yet to get burned.

      Every serious development project I've been on which is centered on MS technology, has been plagued with MS bugs. In my book, any developer which willingly picks MS as their technology base is very low on the totem pool because it proves they simply don't have the experience to be allowed to pick the technology base.

      The only tool suite I've seen which is consistently worse than MS' is Wind Rivers'. Now there is a company which needs to be put out of business. Seems you have to pay large sums of money for them to fix their own compiler bugs which they otherwise refuse to do.

      And oh...hehehehehehehehe. Just in case you missed it the first time.

    9. Re:I'll show you mine if you.. by Anonymous Coward · · Score: 0

      Once again a moderator proves he has no idea what the word "troll" means. Shame on you moderator for not doing your job correctly. Either you misread what he posted or you are abusing your mod points. +1 Funny, +1 Insightful, or +1 Informative, or simply leave it alone is the proper thing to do here.

      If I had the mod points I'd give them to you. The slashdot crowd has really gone down hill over the last couple of years.

    10. Re:I'll show you mine if you.. by fitten · · Score: 5, Informative

      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'.

    11. Re:I'll show you mine if you.. by TheRaven64 · · Score: 4, Interesting

      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).

      --
      I am TheRaven on Soylent News
    12. Re:I'll show you mine if you.. by hoppo · · Score: 2

      Typically, I've found that people who default all blame to "the framework" tend to be careless, lazy developers who refuse to admit that the problem resides with their own code.

      While it's unfortunate that you're so tightly bound to Windows when selecting .NET as your platform (although once mono adopts 3.0 it will be viable IMO), the .NET framework itself has been pretty solid. I've been part of some pretty sizable development efforts where .NET was the platform of choice -- everything from server applications to windows GUI applications to web applications -- and in all those projects we have found the platform itself to be quite reliable.

      What impresses me with .NET is it allows you to write truly orthogonal and very testable code. Your generic rant against the great evil Microsoft suggests you don't have the skillset to properly utilize such tools, and then blame your inadequacies on those tools.

    13. Re:I'll show you mine if you.. by Anonymous Coward · · Score: 0

      It's not funny if it's been run into the ground too much, like all of the other anti-M$ posts.

      Besides, why are you posting anonymously, GooberToo?

    14. Re:I'll show you mine if you.. by Anonymous Coward · · Score: 0

      I fucking hate people who complain about mods. If the post is really that great (It's not), it will get fixed by other mods. I've found that slashdot's moderation system works very well, and that includes how sniveling posts like yours get kicked to the curb.

    15. Re:I'll show you mine if you.. by larry+bagina · · Score: 5, Funny

      Next you'll be telling me that I'm not a nerd and this stuff doesn't matter!!!

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    16. Re:I'll show you mine if you.. by NinjaTariq · · Score: 1

      I wouldn't call ANT obscure, it is quite popular and it can be very useful. But i agree it does read like an Ad.

      I feel bad for the bug, but perhaps its an Ad for more stringent testing. People are very quick to blame the GC, but without seeing the code, I wouldn't be as quick. There are reasons you call the GC manually, thats why you have access to it.

    17. Re:I'll show you mine if you.. by hey! · · Score: 1

      I'll show you my perfect autonomous garbage collector when you show me your perfect C++ programmer...

      I again saw under the sun that the race is not to the swift and the battle is not to the warriors, and neither is bread to the wise nor wealth to the discerning nor favor to men of ability; for given enough time and opportunity everybody will manage to turn himself into a screw-up. Victory belongs to the cheapest that is good enough, enough of the time.

      --
      Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
    18. Re:I'll show you mine if you.. by WED+Fan · · Score: 5, Insightful

      Slashdot is a blog not a news source. I wish more people would realize that.

      ...

      News for Nerds. Stuff that matters.

      O.K., I'll bite, what part of that line do you not understand? If /. billed itself as a "blog" then I'd understand your point. However, /. is a corporate based, self-billed "News" site. Whether reader submission driven or not, it is a news site. You are wrong. But, thanks for your thoughts.

      --
      Politics is the art of looking for trouble, finding it everywhere, diagnosing it incorrectly and applying the wrong fix.
    19. Re:I'll show you mine if you.. by Anonymous Coward · · Score: 0

      I submitted an article as an Anonymous Coward and let me tell you: they did edit my entry. They chopped off words that made sense to keep in the entry and added stupid questions.

    20. Re:I'll show you mine if you.. by Blakey+Rat · · Score: 4, Interesting

      Ditto, I submitted an article about an article that was about a survey done of corporations which concluded that corporations would not quickly adopt Vista. (This was before it was released, which frankly is a 'duh'... do corporations quickly do anything IT related?) But anyway... I spent a lot of time and had someone else read over it, attempting to get the *perfect* Slashdot submissions. There were no grammar errors, no spelling errors, the link was directly over the right keywords, etc.

      The Slashdot editor who posted it moved the link so it looked like I was linking to the original study, not the article about the study. It's like they felt compelled to make a change, so they made one even if the change didn't improve the quality of the article.

      I will say that the rest of the text remained unchanged, and really the only problem with the submission is that people who thought they were going to a study were actually going to a newspaper article about a study, but the point is Slashdot editors *do* make changes all the time.

    21. Re:I'll show you mine if you.. by Anonymous Coward · · Score: 1, Funny

      Mine too, they changed the name of the submitter to Roland Piquepaille.

    22. Re:I'll show you mine if you.. by incripshin · · Score: 1

      That closure problem only really exists in IE. I once made a closure loop for fun, and I quickly lost control of the computer. SeaMonkey handled it nicely, though. (I'm not sure about konqueror or Opera.)

    23. Re:I'll show you mine if you.. by budgenator · · Score: 1

      Yeah the decision up-mod or reply, you'll probably come out alright in metamod so I'll post. While I agree that using a new single source technology is much more likely to encounter problems than a more mature solution multi-sourced technology would; the problem was the normal Good'ol Miscroshaft stuff is for sUx0rs but that these guys made a newbie mistake and when they discovered their shit was weak they tried to wezzel around by sticking in a cheap ass work-arrouund rather than trying to fix the real problem. The symptoms were classic for a unreleased resources death spiral, real programmers would have been embarrassed to admit that that problem existsed in public; My name is Bryan Cattle. I'm a graduate in Electrical Engineering from Princeton University Note only alow Princton EE graduates to program coffe pot without competeant supervision.

      --
      Apocalypse Cancelled, Sorry, No Ticket Refunds
    24. Re:I'll show you mine if you.. by dgatwood · · Score: 2, Interesting

      If you're trying to imply that errors can be made in any language, you're right, but the big difference is that leaks in a manually allocated language like C++ are a heck of a lot easier to find and fix than leaks in a language that tries to be smart and "help" you avoid leaks.

      If you're failing to dispose of an object, look at the places where it should be freed and make sure that it is. Generally, there aren't a lot of these places. If you have a dangling reference, it will show up in the form of a crash. The resulting backtrace will tell you exactly what object contains a dangling reference, at which point you just have to track down why the reference was not cleaned up when the object it referenced was freed.

      By contrast, in a garbage-collected language (or a reference-counted language), you usually don't have the ease of tracking down the dangling references, and even when you do, you rarely have a way to tell the computer "I expect this object to go away when I release it; warn me if it doesn't." As a result, tracking down those last two or three errant references can be a pain in the ass, particularly if you have circularly-referenced structures jacking up your reference counts. It's not always easy to figure out which of the eighty tree-structured objects is being referenced. You might have a reference to a leaf of a tree and the parent links are keeping the tree alive, or you might have a reference to the root and the child links are keeping it alive, or you might have a reference smack in the middle of the rightmost branch and the references bubble up and back down.

      Workarounds like "soft" references don't help, either. At best, you could keep a hard reference to every node in the tree in some enclosing object and use soft references inside it, but this is a pretty hackish workaround. Anything short of that and you are forced to handle the case where your "parent" node can suddenly go away if the last hard reference to the top of tree is released. This is probably not desirable.

      Nothing annoys me as a programmer more than having to deal with garbage collection or reference counting on complex data structures. Above a certain level of complexity, the complexity of managing memory yourself becomes less than the complexity of working around the garbage collection and/or reference counting.

      The best of these schemes, IMHO, is an advisory reference counting algorithm in which you make a habit of incrementing an object's ref counter whenever you add a reference to it and decrementing it when you remove a reference. Combined with manual alloc/free, this gives you the ease of tracking down where those references are, while still giving you the ability to test for references on free and generate a warning that "Object 0x46b32158 is still referenced in three places when freed at utilities.c:866."

      Then, you just have to correlate the crash dump with the warnings and you know -exactly- what is going wrong and where the failure is occurring. Better, because you are choosing when to increase or decrease the reference counts, you can pick and choose which references to count, ignoring references between objects in a data structure like a tree and only considering outside references (the ones you actually care about). You can even do smart tricks like keeping a second reference count on the top node in the tree that indicates a reference to a subtree so that your warnings can be more informative. "Warning: tree 0x23421420 has active external references to child node 0x43298470." And so on.

      The point is that by taking these things out of the hands of the language and keeping them in the hands of the programmer, while the actual programming is slightly more complex, debugging is so much easier that it makes up for that extra complexity in terms of robustness, performance, etc. (at least for programs with a certain level of complexity and longevity). I thus view garbage collection as a tool that is primarily useful for very simple programs and detri

      --

      Check out my sci-fi/humor trilogy at PatriotsBooks.

    25. Re:I'll show you mine if you.. by Anonymous Coward · · Score: 0

      A moderately experienced programmer would recognize the problem very easily

      And a really experienced programmer would recognize that coupling your code internally using events rather than function calls is fragile, fraught with side effects, and hard to debug. Event dispatch should be as tightly limited as possible.

      For all its considerable utility, publish/subscribe is probably the most easily abused design pattern there is, and it is almost never necessary. Merely convenient for inexperienced developers who have never been caught by the non-local dependencies it creates.

    26. Re:I'll show you mine if you.. by LordEd · · Score: 1

      If you read the article, the bug was a result of coding error. My take on the brief description is they added a handler to an object that lost reference. The handler was never removed. That means the object was still in scope because it was tied by the event handler, and therefore is never garbage collected.

      Poor programming can be done in all languages.

    27. Re:I'll show you mine if you.. by PermanentMarker · · Score: 1

      hm yes slashdot is not realy nice to its users always the same people seam to post here. And this problematic web interface, is that an example of linux / unix ?? Whoahahah, they should hire a real web programer and use a decent OS Perhaps keeping in mind this original story their software runs on an OS wich had performance measurement tools inside it's core. They could have used that to determine the cause, i do this often. To detect bugs in other companies software. But as often software developers dont look beyond their own code, since the rest of the IT is abacadabra to them, they can create only projects dealing with their own code. More often they even bypass the people who would gonna use it. I find this to be verry amazing and amusing. As it's all about mis communications, this whole story and how slash dot is using it.

      --
      I know you're out there. I can feel you now. I know that you're afraid. You're afraid of us. You're afraid of change.
    28. Re:I'll show you mine if you.. by asills · · Score: 3, Insightful

      This "article" also shows why you don't let college students write productions systems.

      "We set a timer to restart the computer after 40 minutes".

      Wait. What? Really? That's classic programming by accident. "I added one and it started working, so I moved on."

      --
      -- What did Spock find in Kirk's toilet? The captain's log.
    29. Re:I'll show you mine if you.. by Ant+P. · · Score: 1

      And with the new firehose thing, it looks like they're not even doing the submission accepting part any more.

    30. Re:I'll show you mine if you.. by JebusIsLord · · Score: 4, Informative

      Its quite clear in the article that they forgot to unregister their "deleted" objects from events. Since they were still registered, they weren't garbage collected. And rightly so. This was THEIR programming mistake, and has nothing to do with a GC bug in C# or any such thing. Fuck slashdot is pissing me off these days... as soon as they see a story that could be spun as "Microsoft screwed up!", they publish it withouth any fact-checking (or even reading the goddamn article!).

      I wonder is MS could sue Slashdot for slander?

      --
      Jeremy
    31. Re:I'll show you mine if you.. by Durandal64 · · Score: 1

      The best of these schemes, IMHO, is an advisory reference counting algorithm in which you make a habit of incrementing an object's ref counter whenever you add a reference to it and decrementing it when you remove a reference. Combined with manual alloc/free, this gives you the ease of tracking down where those references are, while still giving you the ability to test for references on free and generate a warning that "Object 0x46b32158 is still referenced in three places when freed at utilities.c:866."
      Objective-C has a similar scheme, but the object is automatically freed when the reference count reaches 0. You simply increment and decrement the reference count as you work with the object. To me, that's the best compromise between automatic garbage collectors and purely manual memory management.
    32. Re:I'll show you mine if you.. by petermgreen · · Score: 1

      If you're failing to dispose of an object, look at the places where it should be freed and make sure that it is. Generally, there aren't a lot of these places. If you have a dangling reference, it will show up in the form of a crash.
      probablly.

      The resulting backtrace will tell you exactly what object contains a dangling reference, at which point you just have to track down why the reference was not cleaned up when the object it referenced was freed.
      If you are lucky. If you are unlucky you will currupt memory that has been realocated to something else causing a crash in some code path that is totaly independent of the real error.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    33. Re:I'll show you mine if you.. by pclminion · · Score: 1

      Slashdot has been around since before the word "blog" existed. At the time I joined I considered it a news source. Maybe it's changing, but there are reasons why a lot of us expect better from the front page. It wasn't always like this.

    34. Re:I'll show you mine if you.. by NeverVotedBush · · Score: 1

      "This "article" also shows why you don't let college students write productions systems."

      It also shows why you shouldn't trust Microsoft products for critical work.

      Their 16-bit error in Excel was just another example. I wonder how many people got tripped up by that?

    35. Re:I'll show you mine if you.. by brunoacf · · Score: 1

      A happy Windows user and developer, And PROUD of it!

      Nothing wrong of using or developing MS software, but are you really proud of it?

      Proud of a company that uses weird tactics and the power of its monopoly to totally crush its competition? A company that (to better profit) tries to pervert the idea of the free and open software (and destroy it)?

      No. I could eventually use MS software and even develop (as I said before, nothing wrong with this), but I could never really be proud.

    36. Re:I'll show you mine if you.. by E-Prime · · Score: 1

      If using .NET 3.5 you could simply use the new WeakEvent and WeakEventManager classes that no not keep listeners alive.

      See http://msdn2.microsoft.com/en-us/library/system.windows.weakeventmanager.aspx for details.

    37. Re:I'll show you mine if you.. by jc42 · · Score: 1

      If you read the article, the bug was a result of coding error. ... Poor programming can be done in all languages.

      Quite true.

      However, some languages trick programmers into certain types of errors. In this case, we have a language that is advertised as having an automatic garbage collector, unlike those horrid languages like C and C++. And the programmers were suckered into trusting this claim. So they wrote code with a bug that likely wouldn't have appeared with C or C++, because programmers understand that those languages are "dangerous" in their handling of references to allocated memory, so they tend to learn the gotchas and take them into account.

      One of the common failures in reporting tech problems is not understanding the problems that can be caused by misleading interfaces. It's easy to blame users or programmers when they fail to correctly use an interface whose design, marketing or documentation is misleading. In this case, it's an API whose marketing hype led them to trust the garbage collection. In other cases, it's other pieces of the interface that the users tend to misunderstand for various reasons. Part of the problem is the constant pressure to deliver code, which gravitates against spending the time it takes to study and understand all the gotchas in the underlying system. Time spent studying the system takes away from coding time, and employers don't like to subsidize such time-wasting activity.

      I've preferred to stick with C for this very reason. That language forces me to write code for keeping track of my references. But this means that I don't fall victim to the universal pressure to deliver yesterday by casually using the builtin memory schemes of a language that I don't understand as well as I should. I've looked at C#, but I freely admit that I don't have (and haven't been permitted to have) enough experience with it to make any sort of guarantees about my code.

      OTOH, I'll admit that I've written some rather big apps in perl, tcl and python, and I've never seen a memory-leak bug in any of those languages. Not even in programs that run in the background for weeks or months. Maybe it's because I don't really trust their memory-handling stuff, either, and program in my own tracking to make sure that I know where all the references are. Or maybe it's just been luck. There is a certain element of luck in programming for systems whose inner workings you don't (or can't, in the MS case) fully understand.

      --
      Those who do study history are doomed to stand helplessly by while everyone else repeats it.
    38. Re:I'll show you mine if you.. by Not+The+Real+Me · · Score: 1

      It also shows why you shouldn't trust Microsoft products for critical work.

      If you have ever read Microsoft's EULA for their development tools (C#/VB/.NET/etc.) Microsoft states that their products should *NOT* be used in mission critical systems.

    39. Re:I'll show you mine if you.. by asills · · Score: 1

      Right, because no other garbage collected runtime has this issue.

      --
      -- What did Spock find in Kirk's toilet? The captain's log.
    40. Re:I'll show you mine if you.. by Harald+Paulsen · · Score: 2, Funny

      Or perhaps it is a place where nerds discuss news and stuff that matters.

      --
      Harald
    41. Re:I'll show you mine if you.. by I'm+Don+Giovanni · · Score: 1

      Yeah, according to TFA, that was the entire problem.
      A couple of the comments to TFA say that .NET 3.5 addresses that problem with "weak references", and more specifically, the WeakEvent/WeakEventManager.

      "In .NET 3.5 you can use WeakEvent and the WeakEventManager to avoid this problem. "

      --
      -- "I never gave these stories much credence." - HAL 9000
    42. Re:I'll show you mine if you.. by dbIII · · Score: 2, Insightful

      It's sort of a blog from before the word was thought of and not Reuters.

    43. Re:I'll show you mine if you.. by bm_luethke · · Score: 1

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

      As far as I can tell they are no worse than "normal" news. Planted questions in townhall meetings, political convention members used as "undecided voters" (and you will note in both of those I did not name a political party as it is standard practice for *all* sides including so called "third" parties), individual reporters feelings presented as fact on technical issues, payed "stories" about products, so on and so on.

      While the above is American centric it isn't hard to find it in French, British, German, or any of the "free world" let alone the "semi-free" (like Russia) or the "non-free". Some places are a little better, some places a little worse but over all if you had to live off the differences then you would starve to death. Yea, some may be conservative, liberal, "other", Microsoft centric, linux centric, or whichever way they lean (and from that point of view they are quite different) but that isn't what I'm talking about - I mean honesty and attempting to simply inform people in a fairly balanced manner. It's comical seeing them talk about how unbiased and fair they are (though I think some commentators say it more tongue in cheek and are somewhat making fun of the people they work for).

      At the least everyone pretty much knows how Slashdot is biased and they don't try and hide it. I may very much disagree with that bias, but as bad as it can get it tends to be better than anything higher than local news (and that will vary by quite a bit), not to mention there will be enough readers jumping on them for gross mistakes.

      --
      ------- Sorry about the spelling, I suffer from two problems. Dyslexia makes it difficult to spell well, lazy makes it
    44. Re:I'll show you mine if you.. by Anonymous Coward · · Score: 0

      This is why Weak References exist; to assist with these sorts of problems where you either need a hashtable in which the mapping from key -> value does not count as a reference to value as far as the garbage collector is concerned, or for holding references to event listeners. (Ex: an object A needs to notify B if it exists but A won't explicitly deregister B at any point. You can't just put this task in B's finalizer if the reference from A keeps it from ever being garbage collected. When B is garbage collected, eventually A gracefully fails to notify B and removes it from the list of those that need notification. So, if it's perfectly fine for the notified object to disappear at any time then use a weak reference.)

    45. Re:I'll show you mine if you.. by Hal_Porter · · Score: 1

      O.K., I'll bite, what part of that line do you not understand? If /. billed itself as a "blog" then I'd understand your point. However, /. is a corporate based, self-billed "News" site. Whether reader submission driven or not, it is a news site. You are wrong. But, thanks for your thoughts.

      Well Pravda means 'The Truth' in Russian too, but it usually wasn't.
      --
      echo -e 'global _start\n _start:\n mov eax, 2\n int 80h\n jmp _start' > a.asm; nasm a.asm -f elf; ld a.o -o a;
    46. Re:I'll show you mine if you.. by Anonymous Coward · · Score: 0

      If you consider a language with reference counting but incapable of resolving cyclic structures "garbage collected", you might have a point.

      What you call "soft references" are often referred to as "weak pointers", and are provided by most garbage collected languages... They work just fine for the rare cases where they are wanted - usually simply to let the garbage collector double as a cache manager for some objects you'd like to keep around as long as there isn't memory pressure. They shouldn't be needed for things like you mention.

      But your examples really sound like you're trying to imagine how your experience with non-garbage-collected languages would translated to garbage collected ones. I honestly can't see how your examples would be an issue in any program that was designed properly. Your tree examples just make me think that you've done a horrible job abstracting things.

    47. Re:I'll show you mine if you.. by Firehed · · Score: 1

      And iTunes has something in the EULA about not for use in nuclear missile defense systems, or something to that effect. It's a standard disclaimer. I don't think anything software-based is really truly safe for a mission-critical system; if you must, direct machine code (or assembly if you're not Woz) is probably the only thing that's pretty impossible to have language-related issues.

      --
      How are sites slashdotted when nobody reads TFAs?
    48. Re:I'll show you mine if you.. by Allador · · Score: 1

      It also shows why you shouldn't trust Microsoft products for critical work. Really? Where in the article do you see anything like that?

      If you actually could be bothered to read TFA, you'd see that this was 100% programmer error.
    49. Re:I'll show you mine if you.. by dgatwood · · Score: 1

      That's a relatively easily solved problem, though. For debugging, always build using a 64-bit address space and use a malloc allocator that never reuses addresses.

      --

      Check out my sci-fi/humor trilogy at PatriotsBooks.

    50. Re:I'll show you mine if you.. by harlows_monkeys · · Score: 2, Interesting

      It also shows why you shouldn't trust Microsoft products for critical work

      Since every other garbage collected language, from every other company, would have had the same problem, how does it show that?

    51. Re:I'll show you mine if you.. by frank_adrian314159 · · Score: 1
      This is one of the easiest bugs to create in JavaScript.

      This is one of the easiest bugs to create in any dynamic language. The real problem is that people who've spent most of their time down in statically-typed code with manual memory allocation don't really understand GC. They don't understand that in getting rid of one class of problem (memory deallocation) they've just made another one (non-released references) more prevalent. Any one who wants to properly program a GC'ed environment should first spend a couple years with Lisp or Smalltalk. A monolithic, image-based environment is fairly easy to monitor for memory retention and image growth, and the use of event mechanisms in the UI makes sure you run into the issue fairly quickly.

      --
      That is all.
    52. Re:I'll show you mine if you.. by Anonymous Coward · · Score: 0

      I find it annoying enough to have to learn yet ANOTHER programming language, or further evolution of an existing one. The point is that somehow this kind of mistake should be more difficult, if not impossible to do. Or just please don't bother us with YAPL.

    53. Re:I'll show you mine if you.. by serge587 · · Score: 1

      I hate to tell you, but if you don't like learning you might be in the wrong industry.
      You don't have to learn it if it's such a bother for you, your criticism is akin to criticizing an academic for writing yet another paper on the subject which you have to read.

      If you're such a smart ass then fork Mono or Java and fix it.

    54. Re:I'll show you mine if you.. by drsmithy · · Score: 1

      Proud of a company that uses weird tactics and the power of its monopoly to totally crush its competition? A company that (to better profit) tries to pervert the idea of the free and open software (and destroy it)?

      A company that behaves like every other one, just with more impact than most.

    55. Re:I'll show you mine if you.. by canuck57 · · Score: 1

      So what if it is a shameless plug. Some MS coders decided to ignore the rules, turn off their brains and got caught by POS programming styles... I agree though, not really news but just another reason why C#, Java and other lazy engineering/programming styles should not be used in embedded systems development, period. Add them to the list of casualties. Road kill if you get the pun.

      Hopefully he will learn the important lesson of embedded systems/controllers development of "Do not do uncontrolled memory allocation at run time" and if the language does not support this rule it is unsuitable. If the programmers don't understand another that is suitable, then they too are unsuitable. (BTW this includes ANY OS, not just MS ones).

    56. Re:I'll show you mine if you.. by MickDownUnder · · Score: 2, Insightful

      You are right, the wording of this article is extremely misleading.

      There was a memory leak but it was due to their code, not with the Microsoft .NET Framework. Specifically their code was creating objects that were never being garbage collected as they were still being referenced in their code, i.e. they forgot to dispose and unsubscribe from events to objects that were still active. This is a really simple mistake you'd probably find in 40% of newbie programmers C# or Java code. Yes... this sort of problem can occur just as easily in Java (even more easily if you believe Microsoft).

      Now on to flaming slashdot...

      I really think Slashdot should pull articles like these either completely or at least from the front page when they realise they're misleading or factually incorrect.

      This story simply isn't news worthy, it's not even interesting for anyone half competant in .NET development. It reflects really poorly on slashdot and reduces the sight to the quality of your average web blog. In summary it's a waste of everyone's time.

    57. Re:I'll show you mine if you.. by Pope · · Score: 0, Offtopic

      What did Riker find on Picard's web site? Captain's blog.

      --
      It doesn't mean much now, it's built for the future.
    58. Re:I'll show you mine if you.. by NotZed · · Score: 1

      I would argue that it is a bug in the language because it is simply a language feature, and leaks are a pretty poorly documented side-effect of using said feature.

      The object life-cycle is poorly documented - but then again just about everything else in .net is poorly documented as well.

      --
      _ // `Thinking is an exercise to which all too few brains
      \\/ are accustomed' - First Lensman
    59. Re:I'll show you mine if you.. by neonsignal · · Score: 1

      I guess the problem is that people think that garbage collection prevents all out-of-memory problems. Memory leaks are just one cause of runaway memory use; a common one to be sure (just like stack underflow and overflow were common before we went from assembler to procedural languages). So I agree, I think it was a bit unfair to blame C# (much as I am irritated by the philosophy of that particular language).

    60. Re:I'll show you mine if you.. by gr8scot · · Score: 1

      You're right, it's not the garbage collector's fault! When you're writing code for a DoD project, "Microsoft said they automated that" is a pathetic excuse, which makes it not much of a sales pitch, either. As a news article, this was less interesting than the Discovery Channel special, but as an advertisement, it was laughable. This doesn't tell me that AntEater or whatever it's called is the greatest thing since JIT compilation, it only tells me that the programmers on this project probably had some experience with C/Java/C++, but didn't learn the peculiarities of C# beyond the marketing hype, and specifically didn't have a solid understanding of what its garbage collection would do for them and what it wouldn't. In other words, they depended on the technological commodity -- the "out-of-the-box experience", if you prefer -- to do more for them than it really could. They expected it to do their thinking, and because of that they didn't win. What I get from this story is that without AntHill, the same team would have set an even more grandiose goal than their unique use of "stereo vision, as opposed to scanning lasers, to detect and range obstacles", and they would failed to account for a similarly minor detail. What they really should have done is more fully account for the team's collective technical limitations before deciding how elaborate their final product would be. No "out-of-the-box solution", including so-called "out-of-the-box thinking" will do that for you.

      --
      All 19 hijackers were known terrorists 09-10-2001. Lack of FBI intelligence does not justify warrantless wiretaps..
    61. Re:I'll show you mine if you.. by Zarf · · Score: 1

      If you have ever read Microsoft's EULA for their development tools (C#/VB/.NET/etc.) Microsoft states that their products should *NOT* be used in mission critical systems.

      Anything with non-monotonic timing should be avoided in any system that has sub second timing issues. Such as system might be a robot that drives a car. That means that windows derived products should never be used in real time sensitive systems. Microsoft knows this and doesn't pretend otherwise. Microsoft products are simply unusable for many embedded applications.

      I'm not just saying this to bash Microsoft, it's a known issue with windows based systems. They simply aren't suitable in places where sub-second timing is important. Take a look at this post if you don't believe me: https://lists.ntp.org/pipermail/hackers/2007-May/002888.html The salient point from the post is:

      The system time on windows takes rather big steps (typically 100Hz, but 1000Hz and 64Hz are also not impossible, it just varies from system to system). That much variability will kill you in a fighter jet or missile. In time as systems become faster and faster the chaotic variability of the windows systems becomes less and less important since the variable length actions take shorter and shorter amounts of time to resolve. In time maybe the non-monotonic timing in Windows will become less important to real time systems programmers but I find that hard to believe.
      --
      [signature]
    62. Re:I'll show you mine if you.. by plague3106 · · Score: 1

      It also shows why you shouldn't trust Microsoft products for critical work.

      No, it means developers need to be aware what a reference to an object is. In this case, the objects they THOUGHT were being freed weren't because said objects were either generating or listening for events. The GC was correct in its behavior.

    63. Re:I'll show you mine if you.. by godefroi · · Score: 1

      I got to work last friday and the coffee machine had been dutifully making coffee all night. The entire area was soaked. I don't think letting them at the coffee pot would be that great of an idea. Maybe a door hinge. For a closet. In an abandoned building. Yeah, that sounds ok.

      --
      Karma: Poor (Mostly affected by lame karma-joke sigs)
    64. Re:I'll show you mine if you.. by Anonymous Coward · · Score: 0

      If you're such a smart ass, then what industry are you so sure I'm in?

      In fact I'm not in software development for exactly THIS reason! I've been out of it for over 8 years and I'm much happier, more productive, and make more money, have less hassle, happier bosses/clients/people who pay me- it's a win-win! I get to be creative, people LOVE my ideas and suggestions, I get to innovate- the list goes on and on.

      But being a smart ass, I do still read slashdot, keep up with sw dev., and snicker at all of the mess and all of the pawns being pushed around. :-P

      Oh by the way, I love learning; I just don't like being a pawn and being FORCED to learn at the various kings' whims and demands.

      Oh, and for the record, I did mostly C, x86 Assembler, and some specialized BASIC, and when you get to develop in a stable environment, you can get REALLY good, efficient, and bug-free.

      It's exactly problems like this article describes that convince me I made the right decision to get of sw. :)

    65. Re:I'll show you mine if you.. by ClosedSource · · Score: 1

      "Slashdot is a blog not a news source."

      Sure, that's why they call each main thread a "story".

  2. Well, there's your problem! by feepness · · Score: 5, Funny

    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.
    1. Re:Well, there's your problem! by johannesg · · Score: 4, Funny

      No no, that would be something along the lines of printing out the code and then throwing darts at the listing to figure out the incorrect line. I hear it is popular in Redmond, although they reputedly use chairs instead of darts.

    2. Re:Well, there's your problem! by maxwell+demon · · Score: 5, Funny

      No no, that would be something along the lines of printing out the code and then throwing darts at the listing to figure out the incorrect line. I hear it is popular in Redmond, although they reputedly use chairs instead of darts. That makes sense: Since chairs are larger than darts, you have a much greater chance to hit the bugs.
      --
      The Tao of math: The numbers you can count are not the real numbers.
    3. Re:Well, there's your problem! by _merlin · · Score: 3, Insightful

      I'm guessing you wanted me to laugh, but in a highly parallel system, going through the code line by line is often the most effective way of finding a problem. When you catch the bug on a running system, you can see the state it's got itself into. But to figure out how it could have got there, you need to read and analyse the code. People are often far too eager to jump into the debugger when critically analysing the code is often a better solution.

      It obviously doesn't work in situations like this where the bug is in the runtime and not the application.

    4. Re:Well, there's your problem! by __aasmho4525 · · Score: 5, Informative

      just to be clear, THE BUG WAS NOT IN THE RUNTIME, not by any stretch.

      there are very clear constructs in place in the language/runtime to allow any object to unregister itself from event registrations it initiated.

      this was VERY MUCH a bug in the end-user software, not the runtime (i've written code almost IDENTICALLY to this and blew lots of time having made this same mistake).

      the only thing the runtime could do to protect the idiot developer (myself included) is automagically make all event references WEAK references, but that has plenty of undesirable side-effects too... in clr, you can do this yourself if you're so inclined... (just like in a JVM)

      cheers.

      Peter

    5. Re:Well, there's your problem! by Anonymous Coward · · Score: 0

      Actually, this was brought in during the company's "Balmerization" period, when Steve Balmer came in from WWF pro wrestling. He liked throwing chairs at things (and people) at his previous job at WWF and thought it might be a good way to both debug and relieve stress in coding teams.

    6. Re:Well, there's your problem! by Peter+La+Casse · · Score: 1

      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.

      Code inspections and walkthroughs are actually effective ways to find bugs. When you debug from a symptom you have to trace back and figure out where the bug is happening, but when you have multiple people manually working through what should happen you can detect problems directly.

    7. Re:Well, there's your problem! by Anonymous Coward · · Score: 0

      Read his post again. He didn't say it was. Do you often hear voices in your head...?

    8. Re:Well, there's your problem! by timeOday · · Score: 1

      in a highly parallel system, going through the code line by line is often the most effective way of finding a problem.
      And that's basically the problem with parallel software... the best way to debug it is still very poor. I don't take on writing parallel code lightly; in fact I avoid it when possible. Go ahead and deride me, but I know it's not just me because I have consistently, over the course of many years, noted that threaded programs almost always have related bugs.
    9. Re:Well, there's your problem! by SamuraiMike · · Score: 1

      This may be the least effective method of debugging in existence. Actually, code reviews are a best practice in software development because they can have very good defect discovery rates in the late stages of development compared to other defect discovery strategies.
    10. Re:Well, there's your problem! by asg1 · · Score: 1

      Not to be a troll, but that was probably one of the greatest exchanges i've ever read on Slashdot... thank you for making me spit my Cheerios back in to my bowl from laughing so hard.

    11. Re:Well, there's your problem! by SilentBob0727 · · Score: 1

      Mod parent insightful please

      --
      Life would be easier if I had the source code.
    12. Re:Well, there's your problem! by ILuvRamen · · Score: 0

      I dunno why you're surprised. As a professional programmer (and a good one) I can say that these people are possibly the worst programmers on Earth. Ignoring the whole print out the code and read it on paper thing, if they can't figure out something so basic as if the computer gradually slows down, the memory is running out, they shouldn't be programming. I guess it never occured to them to ohhhhh you know, maybe check and see how much open memory there was when they were having the problem. I hope their car goes crazy and runs them over so they can stop disgracing Princeton.

      --
      Google's Super Secret Search Algorithm: SELECT @search_results FROM internet WHERE @search_results = 'good'
    13. Re:Well, there's your problem! by FreeGamer · · Score: 5, Informative

      It obviously doesn't work in situations like this where the bug is in the runtime and not the application. RTFA. FTFA:

      Though we thought we had cleared all references to old entries in the list, because the objects were still registered as subscribers to an event, they were never getting deleted. We added one line of code to remove the event subscription and, over the next three days, we successfully ran the car for 300 miles through the Mojave desert. As another poster points out, this is just an advert for a profiler, which helps people who use coding practises that they did not initially fully understand. As much as I wanted it to be a bug in the C# runtime, it's just another PEBKAC issue. The /. article introduction was wonderfully ambiguous on this point, if anything it was inflammatory ("C# memory leak"). Poor article selection if you ask me, but it's been many years since the /. editors genuinely cared about the content on this site rather than the number of hits/adclicks.
    14. Re:Well, there's your problem! by Jarjarthejedi · · Score: 1

      And since it's Microsoft code your chance of missing a bug is minuscule. *Bada Bing*

      --
      There are two kinds of fool One says 'This is old therefore good' Another says 'This is new therefore better'- Dean Ing
    15. Re:Well, there's your problem! by v1 · · Score: 1

      In years gone by, the correct way to deal with compiler bugs is to compile a bit of your code that's known to be buggy (while making it as small as possible) and then examine the assembly it generates for bugs. This approach would have worked for them, but due to the bloated code generated by most compilers, (and sometimes by the very structure/nature of compiled code) this may have been an effective, yet impractical undertaking.

      I miss the days of finding bugs in compilers. Many many years ago a compiler named Merlin Pro (points if you have any idea what platform THAT was for) I pulled out my hair for a few hours on why something would not run properly. Turns out one instruction could reference an address by native 16 bit OR 8 bit addressing if the address just happened to resolve (calculated addresses only) in zero-page. (which made for faster access and saved a byte in the instruction) This was obviously a good optimizing step, but sadly the compiler did not take the possible shortening of the instruction after calculation into account when building its label branch table for addresses assigned after that point in the code, making branches across that instruction miss by one byte. Fortunately, in that case, the results were catastrophic and immediate and made for easy analysis once the problem was recognized. Probably not so easy with a memory leak in a variant of C.

      But really, any experiencecd programmer should not rule out the compiler "because it's not supposed to DO that". That deserves an "oh, you must be NEW here..."

      --
      I work for the Department of Redundancy Department.
    16. Re:Well, there's your problem! by ravenlock · · Score: 1
      So what exactly does it read here then:

      It obviously doesn't work in situations like this where the bug is in the runtime
    17. Re:Well, there's your problem! by DaveAtFraud · · Score: 4, Interesting

      When writing parallel software, you need to treat the interactions between different threads of execution the same way you treat interactions between different code elements. This is a *DESIGN* issue. That's why debuggers aren't usually useful for finding such problems. Debuggers let you find sequential logic errors but rarely give you any insight into state coupling errors that only occur during real-time execution of the program. This is true whether the error occurs between different threads of the same code or different processes of the overall program. For some reason, people are particullarly unable to see such problems between different threads.

      I first ran into this sort of problem in 1983 when working on a CDC mainframe. The only way to find the bug was the line by line analysis method since even compiling the code with debug caused it to run slower and the nature of the problem changed. That's as much detail as I remember.

      I expect to see a lot more of these kinds of errors pop up as multi-core CPUs become more prevalent (true parallel execution) and people continue to assume that they can just crank out code without taking the time to understand the design. I'd also expect the prevalence of multi-core processors to create a demand for more parallelism. If you don't take advantage of the additional cores, your program will only be as fast as if it were on a single core system. If the competition can create a program that uses the additional cores, your program will seem slow.

      Cheers,
      Dave

      --
      They that can give up essential liberty to obtain a little temporary safety deserve neither safety nor liberty.
      Ben
    18. Re:Well, there's your problem! by TheRaven64 · · Score: 1

      Parallel and threaded do not mean the same thing. When you create a new thread, you increase the debugging complexity of your program by a polynomial factor due to the increased potential for interactions. If you use a system based on a CSP (or similar) model then this is not the case; interactions must be mediated and so you get only a linear increase in debugging complexity. This is why I can happily write Erlang code that scales up to a few thousand concurrent tasks but hate writing threaded code in pure imperative languages (C, Java, etc.) unless I have a framework that mimics the Erlang execution model.

      --
      I am TheRaven on Soylent News
    19. Re:Well, there's your problem! by Bill,+Shooter+of+Bul · · Score: 2, Funny

      I have noted that programs of non-trivial size almost always have bugs in them. The secret to writing parallel code, is to create multiple personalities, one for each thread. Then you just emulate the code in you parallel mind, and its easy to see the problem.

      --
      Well.. maybe. Or Maybe not. But Definitely not sort of.
    20. Re:Well, there's your problem! by Anonymous+Brave+Guy · · Score: 2, Insightful

      I think there's a rite of passage in programming. First, you see a bug and immediately assume your code is right and the compiler is wrong. With a little experience, you learn that it's actually a darn good bet that your code is the thing with the problem. With a lot of experience, you learn that while it's a darn good bet, on rare occasions the compiler really does get it wrong, but that it usually takes a horrendously long, assembly-level debugging session to prove it.

      Much the same is true of the standard library that comes with your programming language, or any high quality third party library you use. Some of these are considerably more robust than others, but usually if it's something thousands of projects are using, it's going to be your project code that's wrong rather than the library.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    21. Re:Well, there's your problem! by NinjaTariq · · Score: 1

      Perhaps they gave it to a savant who could compile, unit test and run code that he read on paper in his head. I think that would be an awesome way to test.

    22. Re:Well, there's your problem! by Marcos+Eliziario · · Score: 3, Funny

      Mod myself funny, please.

      --
      Your ad could be here!
    23. Re:Well, there's your problem! by Anonymous Coward · · Score: 0

      No no, that would be something along the lines of printing out the code and then throwing darts at the listing to figure out the incorrect line. I hear it is popular in Redmond, although they reputedly use chairs instead of darts.

      You must also speak the following mantra while throwing the chair: "I will fucking kill you!"

      Surprisingly, it works in 1/2 of all patches.

    24. Re:Well, there's your problem! by v1 · · Score: 1

      I'd have to agree with that. I pondered for a bit and realized I've ran into two other examples in the past. AppleSoft basic, do a gosub within a triple nested for loop and the stack overflows, and zero-page gets "clobbered" as the hint I read put it. Bad Things happen after that, usually requiring a reboot.

      Not quite so long ago I wrote a pascal program that was very heavy on the use of pointers, and as a shortcut and to speed it up I was digging very very deep with pointers. I think for one line I had 7 levels of indirection. I was up until 11pm in the lab trying to figure out why it would work when I was tesing the parts of it but not with the command all together. Took it to a prof and we both studied it for about an hour. "This SHOULD work....it's complicated, but it's CORRECT." We then started expermenting, and found that the VMS version of the pascal compiler could not produce correct code with more than 6 levels of pointer indirection in an assignment. No crash, just bad results.

      There were no "fixes" for either of these issues. You just had to recognize the limitation of the compiler/interpreter and not do things that you knew it was going to choke on.

      Good lord look what google found... http://users.rowan.edu/~johnsonk/KHJcomputers.html

      Q. Dear Uncle Louie -- I'm having trouble with my checkbook program. It seems that when I do a gosub from within a triple-nested loop, the stack overflows and zero-page gets clobbered. What should I do?
      A. How should I know?


      heh... haven't seen that in YEEEEEARS. The logo says 1980. On a few of their manuals it didn't say "software", it said "indoor sports".

      --
      I work for the Department of Redundancy Department.
    25. Re:Well, there's your problem! by DrJimbo · · Score: 1

      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.
      Decades ago I was writing machine code for an Intel SBC-80 single board computer based on their 8080 processor. My "terminal" was a rackety old teletype that printed on rolls of aged yellow paper. One of the few debugging aids I had was printing out a hex dump of the machine instructions. IIRC, the instructions could be one, two, or three bytes long so I would first circle the bytes grouping them into instructions, then dis-assemble the instructions by hand, and then finally check all the addresses by hand.

      This provided very strong motivation to write correct code from the start. BTW, I learned to leave small gaps between routines so I wouldn't have to relink everything if I needed to squeeze a few more bytes in somewhere.

      Anyway, one program was driving me bananas. I couldn't figure out why it wasn't working properly. I dis-assembled my printout over and over again and I could not find any mistake yet the code did not work. Then I figured out that if one particular instruction was wrong (a call instead of a jump perhaps) it would account for the errant behavior, yet the instruction was correct in the printout. So I printed out another hex dump and sure enough, that instruction was wrong. It turned out that I had made a typo when typing in the hex codes and then the damned teletype made a symmetric typo converting the mistyped character back to the one I thought I had typed in, hiding my mistake. I think it was actually a perfect flaw in the yellow paper that made a "3" look like a "B".

      --
      We don't see the world as it is, we see it as we are.
      -- Anais Nin
    26. Re:Well, there's your problem! by Anonymous Coward · · Score: 0

      Actually, code reviews are a best practice in software development because they can have very good defect discovery rates in the late stages of development compared to other defect discovery strategies.

      Bingo, sir.

    27. Re:Well, there's your problem! by timeOday · · Score: 1

      This may sound horrible, but having to actually understand code in order to work with it is a recipe for disaster. Don't get me wrong, I love to get "in the zone" and write some perfectly handcrafted code. But the fact is, some bozo is going to work on the code sooner or later. He's not going to really understand it, instead he's going to use the "generate and test" method of problem-solving, i.e. slop some code in there and then debug it until it seems to work. That bozo could even be you, when at some later date you hardly remember the code and have a short amount of time to modify it. I haven't discovered any way to cope with the problem, except to code in a very obvious way.

    28. Re:Well, there's your problem! by bar-agent · · Score: 1

      The secret to writing parallel code, is to create multiple personalities, one for each thread. Then you just emulate the code in you parallel mind, and its easy to see the problem.

      In other words, you'd have to be crazy to write parallel code? :-)

      --
      i'd hit it so hard, if you pulled me out you'd be the king of britain [bash.org]
    29. Re:Well, there's your problem! by Man+On+Pink+Corner · · Score: 1

      Many many years ago a compiler named Merlin Pro (points if you have any idea what platform THAT was for) I pulled out my hair for a few hours on why something would not run properly.

      Sounds like some 65816 code for a IIgs. Merlin was an assembler, technically, not a compiler per se.

    30. Re:Well, there's your problem! by budgenator · · Score: 2, Insightful

      hopefully you programmed things so if the accelerator_actuator object hasn't heard from the speed_control object in a while it returns to an idle mode rather than bizercko autonomus vehicle peddle to the metal mode, like the Princeton guys did.

      --
      Apocalypse Cancelled, Sorry, No Ticket Refunds
    31. Re:Well, there's your problem! by darkpixel2k · · Score: 2

      And since it's Microsoft code your chance of missing a bug is minuscule. *Bada Bing*

      ...and if MS switched to programming in python, you'd even be able to hit white-space and hit bugs.

      --
      There's no place like ::1 (I've completed my transition to IPv6)
    32. Re:Well, there's your problem! by ticklish2day · · Score: 1

      Agreed. It's a bunch of amateurs writing "production-quality" code and expecting it to be flawless the first time. "Yes mommy, it works! I wrote the code through the night and look, she drives! I don't know why she keeps dying every 40 minutes - must be a Microsoft bug. Those idiots can't even write a decent compiler."

      From the description, it sounds very much like their objects were being promoted through to Gen2 and staying alive because they were referenced from the application root. They could have attempted to alleviate this by switching to WeakReferences or queuing calls to run a full garbage collection across all generations. And, hopefully, they were not using finalizers (whole new ball game). Also sounds like they had design issues. I'd like to know why they subscribed already seen obstacle objects to an event. Is the source available somewhere?

      If only they had read Jeffrey Richter's book or the articles on garbage collection on MSDN, they could have got a faint idea with what may be going wrong. Remind me to never ever hire Bryan Cattle as a software dev. He deserves to be in sales or marketing, touting his Princeton credentials and selling bars of soap.

      On a much more interesting note, which version of the framework were they using on Windows? Or were they using mono on Windows/Linux?

    33. Re:Well, there's your problem! by Schraegstrichpunkt · · Score: 1

      With a little experience, you learn that it's actually a darn good bet that your code is the thing with the problem.

      Unless you're writing code in PHP. Then you learn the opposite. :(

    34. Re:Well, there's your problem! by Anonymous Coward · · Score: 0

      Ignoring the whole print out the code and read it on paper thing
      What's so bad about that? I do it all the time. It can sometimes be easier to read things on paper than on a computer screen...
    35. Re:Well, there's your problem! by chromatic · · Score: 2, Insightful

      This may sound horrible, but having to actually understand code in order to work with it is a recipe for disaster.

      It seems to me that hiring barely-competent monkeys to maintain software you care about is the real problem.

    36. Re:Well, there's your problem! by nametaken · · Score: 1

      It seems that in Redmond you could hit the bug by firing a single electron at random into a mural of code the size of Building 17... without the double slit barrier.

    37. Re:Well, there's your problem! by smallpaul · · Score: 2, Informative

      First: The bug was not in the runtime. It was a simple programming bug. Second: the bug had nothing to do with parallel processing. It was an object leak due to event handling. The fastest way to solve it would have been to print out the object graph of the program after it had started running and then again after it had "slowed down". They would have seen a particular class of object had become much more numerous over time. That's you're leaker. Memory leaks ARE often easier to track down empirically rather than by just reading the code over. After all, the bug is that the state of the application is in an unwanted state. So why wouldn't you want to characterize the nature of the unwanted state (not just "memory is gone" but "event listener objects are leaking")?

    38. Re:Well, there's your problem! by petermgreen · · Score: 1

      This may be the least effective method of debugging in existence.
      I have had to use it once. I was designing a programmer for the pic18f452 (something I don't reccomend btw, using an existing programmer design is much easier). At well over a hundred clocks before anything interesting happened following the programming waveforms on a scope was not feasible so the only option was to repeatedly go through my code comparing it to the programming spec until things work.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    39. Re:Well, there's your problem! by feepness · · Score: 1

      Anyway, one program was driving me bananas. I couldn't figure out why it wasn't working properly. I dis-assembled my printout over and over again and I could not find any mistake yet the code did not work. Then I figured out that if one particular instruction was wrong (a call instead of a jump perhaps) it would account for the errant behavior, yet the instruction was correct in the printout. So I printed out another hex dump and sure enough, that instruction was wrong. It turned out that I had made a typo when typing in the hex codes and then the damned teletype made a symmetric typo converting the mistyped character back to the one I thought I had typed in, hiding my mistake. I think it was actually a perfect flaw in the yellow paper that made a "3" look like a "B". I got 11 replies to my little joke and I just wanted to say yours was the most interesting.
    40. Re:Well, there's your problem! by lgw · · Score: 1

      This is the rite of passage for all engineering really: first you assume that you're smarter than "the book" and any problems are with the overly-complex "by the book" way that the old fossils do things.

      Then you realize that the world is more complex than your mental model, and start assuming that "by the book" works and any problems must be in your engineering.

      One day your mental model exceeds "the book", and you genuinely find limitations in the "by the book" approach, and can push the state of the art - you're now the next guy to write "the book".

      --
      Socialism: a lie told by totalitarians and believed by fools.
    41. Re:Well, there's your problem! by ConceptJunkie · · Score: 1

      I always thought they just threw another 20 megs of code in to work around the problem.

      --
      You are in a maze of twisty little passages, all alike.
    42. Re:Well, there's your problem! by Anonymous Coward · · Score: 0

      You are a fool.

    43. Re:Well, there's your problem! by I'm+Don+Giovanni · · Score: 1

      "As much as I wanted it to be a bug in the C# runtime, ..."

      Um, why would you *want* the bug to be in the runtime such that it would be a widespread issue?
      This is what I don't understand about slashdotters. True tech geeks would want *all* technologies to work and succeed. Rooting for technologies to be bad or to fail seems backward. Yet I see it all the time here: people rooting for certain video games to be bad/fail, certain mp3 players to be bad/fail, rooting for certain OSes, apps, programming languages, programming frameworks, web services, phones, robots, optical disc formats, etc to be bad/fail.

      A concrete example is that many iPod fanboys root for all other mp3 players to fail in the marketplace, and I have to scratch my head and wonder why?

      Why not instead root for everything to be good? It gives you more options. For example, if all games are good, that's more games one can enjoy. But many root for certain games to be bad instead. I guess it's a geek thing.

      --
      -- "I never gave these stories much credence." - HAL 9000
    44. Re:Well, there's your problem! by Anonymous Coward · · Score: 0

      And thank *you* for the charming image....

    45. Re:Well, there's your problem! by Marcos+Eliziario · · Score: 1

      Thanks, mods. If any other moderator feels like modding my comment funny, please use my parent comment up to +5. If parent is +5 funny, use this comment instead. Thanks again!

      --
      Your ad could be here!
    46. Re:Well, there's your problem! by Anonymous Coward · · Score: 0

      To duplicate the same "memory leak" in Java add a lot of listeners to your main JFrame in a swing app and watch as the memory footprint just grows and grows and grows.

      Better languages can only help stupid/ignorant people so much.

    47. Re:Well, there's your problem! by Randolpho · · Score: 1

      Um, why would you *want* the bug to be in the runtime such that it would be a widespread issue?
      I have to wonder if you've been living under a rock or something. This is SLASHDOT! Obviously, he wants it to be a bug because it's popular on Slashdot to hate Microsoft. Typically, this is done with references to the Borg, or (the one that really makes them cry) replacing the 's' character with a '$' character, like this: M$. Micro$oft.
      --
      "Times have not become more violent. They have just become more televised."
      -Marilyn Manson
  3. Slashvertisement by shartte · · Score: 5, Informative

    The linked "article" is just a "sponsored review" for a C# profiler...

    1. Re:Slashvertisement by JanusFury · · 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...

      --
      using namespace slashdot;
      troll::post();
    2. Re:Slashvertisement by ceeam · · Score: 3, Insightful

      Of course it has nothing to do with differences between "managed code" and native, right?

    3. Re:Slashvertisement by slashdot.org · · Score: 4, 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.

    4. Re:Slashvertisement by Florian+Weimer · · Score: 1

      All this stuff sounds either very naive or very marketing. You choose.

      Can't you just create a heap dump at two or three points in time, create a histogram of object types, look at the types whose objects are apparently growing unbound, and examine what kind of objects are pointing to such objects, keeping them alive? No need for fancy, invasive tools.

      Or doesn't Microsoft's C# come with a built-in heap dump facility and some analysis/browser software? This would be a pitty because such problems do occur in practice and are rather difficult to debug without proper tools.

      Tying the reboot to time elapsed, and not working set size is a serious WTF, though. Rebooting as some sort of uber-garbage collector makes a lot of sense, but you really should make sure that you do it if and only if you actually need it.

    5. Re:Slashvertisement by WeirdJohn · · Score: 3, Insightful

      The whole 'reboot to fix it' is a methodology that we're going to see more and more of, as students who have only ever been exposed to windows platforms become more and more pervasive.

      Kinda scary when they start writing systems for medical applications, industrial controllers and power supply chain management, let alone nationwide air traffic monitoring or emergency services interactions management.

        "Hang on, we have to reboot our systems every 6 hours in order to manage this natural disaster - You can be advised when the flood waters will peak in about 15 minutes - did you say the bridge is washing away, and your phone lines are about to fall down? Ring us back in 15 minutes after the systems finish rebooting"

    6. Re:Slashvertisement by moogs · · Score: 0

      no, no, the whole point of this is to imply that m$ is teh evil1!!!!, no matter what the facts really are. You must be new here :)

      --
      I have bad karma. What do I care what you think?
    7. Re:Slashvertisement by GrievousMistake · · Score: 1

      All this stuff sounds either very naive or very marketing. You choose. I choose to think it's very naive of them to agree to be very obvious marketing shills.
      Personally I think it reflects badly on the writer to appear so excited over being able to diagnose a simple dangling reference bug. Maybe they figured no-one would ever see it.
      It's fine to have sponsors (the company in question is an official PAVE sponsor), but cheapening yourself like this.. cheapens you.
      --
      In a fair world, refrigerators would make electricity.
    8. Re:Slashvertisement by jmccay · · Score: 5, Insightful
      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.
      --
      At the next eco-hypocrisy-meeting, count the private jets used to get to the meeting. Should be interesting to see that
    9. Re:Slashvertisement by Etrigoth · · Score: 2, Informative

      Indeed it's a great piece of code; the only thing that puts people off is it's apparent complexity - the whitepiper that accompanies it, is a bit offputting too...

      I've had my fair share of experience with ANTs and to be honest, it's been useless in my application. We load controls dynamically in an ASP.Net environment and ANTs refuses to profile them. I've been backwards and forwards with their support team, to no avail. In fact the only thing that happened was me blocking their sales rep from emailing asking if I was prepared to make a purchase yet, when it was plainly obvious it didn't work right for us!

      I've had much better experience with, and strongly recommend, the .Net Memory Profiler, from Scitech software.
      It's saved me so much headache :)

      --
      When we remember we are all mad, the mysteries disappear and life stands explained.
    10. Re:Slashvertisement by Etrigoth · · Score: 1

      You make a good point, but I've just got to say that you don't need a Microsoft Language / OS / IDE to be a bad or lazy programmer.
      In fact, you simply need to not bother trying to understand what you're doing :) ... and be too proud to admit it or realise it :)

      Look around in Googles code search, there are some shockingly bad examples of code in any language you can think of :)

      --
      When we remember we are all mad, the mysteries disappear and life stands explained.
    11. Re:Slashvertisement by h4rm0ny · · Score: 4, Insightful


      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.

      --

      Aide-toi, le Ciel t'aidera - Jeanne D'Arc.
    12. Re:Slashvertisement by AnonChef · · Score: 1

      Could i trouble you for a name of this profiler or a perchance link?

    13. Re:Slashvertisement by ydrol · · Score: 1

      Isnt there an 'advert' tag or similar?

    14. Re:Slashvertisement by samkass · · Score: 2, Insightful

      The new garbage collected languages (C# and Java) seem to be creating coders that don't know the basics of debugging.

      An interesting observation. Java is a lot harder to write bugs in and is easier to debug (with more runtime information), so coders spend a lot less time in the debug cycle and therefore get less experience doing it. So should we design our languages to be obtuse and hard to read (ie. C++) or continue trying to design languages that make it harder to get things wrong?

      Java has made some wrong turns in this regard (ie. autoboxing-- I wonder if we can yank that from the language in JDK7), but in general has done a great job of making it difficult to tie that noose for yourself.

      --
      E pluribus unum
    15. Re:Slashvertisement by Ronin+Developer · · Score: 3, Informative

      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

    16. Re:Slashvertisement by Mr.+Shiny+And+New · · Score: 1

      Autoboxing isn't as big a problem as autounboxing.

      void doSomething(Object a) {} // ...
      int i = 0;
      doSomething(i);

      if doSomething takes an object, you're ok, there's just a hidden memory cost.
      Auto-unboxing is worse:

      Integer i = null;
      i = i + 1; // hidden NullPointerException

      This is where your code has mysterious problems, and when you're reading a line of code and you have no idea why there's an NPE there...

    17. Re:Slashvertisement by ravenlock · · Score: 1

      C# doesn't let you assign null to a boxed value type (you can override this from C# 2.0 on by explicitly using a nullable type).

    18. Re:Slashvertisement by rbarreira · · Score: 1

      I believe he's talking about this:

      http://en.wikipedia.org/wiki/CLR_Profiler

      --

      The AACS key is NOT 0xF606EEFD628B1CA427BEA93A9CA9773F
    19. Re:Slashvertisement by TargetBoy · · Score: 2, Insightful

      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

      We have to teach every new developer to share and reuse code and generally avoid continually reinventing the wheel because the anti-cheating rules in college keep them from learning it there. They were probably required to create it from scratch. There needs to be an upper level class where students are given projects that are impossible to complete in the allotted time unless they reuse code that is readily available.
    20. Re:Slashvertisement by 12357bd · · Score: 1

      I was a good VB programmer. But my VB experience was an eight-month interval between C++ jobs.

      Ha! Bullshit! Everybody knows that mastering VB needs at least 30 years or so of hard work! Eight months is barely enough to start understanding what a variant is. Jesus! :)

      --
      What's in a sig?
    21. Re:Slashvertisement by MillionthMonkey · · Score: 1

      This is a great interview question- a good indicator of experience. I ask interviewees about this all the time (there's an NPE here, can you see it?) and they're either clueless or bitterly familiar with it. And once in a while I still get bitten in the ass by this type of bug. Be careful when you do arithmetic on an integer that you got from a collection.

    22. Re:Slashvertisement by h4rm0ny · · Score: 1

      Ha! Bullshit! Everybody knows that mastering VB needs at least 30 years or so of hard work! Eight months is barely enough to start understanding what a variant is.

      It's not 30 years to learn what a variant is. It's 30 years to bring yourself to use one. *shudder* ;)
      --

      Aide-toi, le Ciel t'aidera - Jeanne D'Arc.
    23. Re:Slashvertisement by wootest · · Score: 1

      Microsoft offers a *memory* profiler with source provided ("CLR Profiler"). The only CPU profiler tuned to .NET work Microsoft offers that I've been able to find is bundled with Visual Studio Team System, which starts at $2300, *if* you have an MSDN subscription that you'd like to renew at the same time.

    24. Re:Slashvertisement by Tim+Browse · · Score: 1

      Reminds me that I used to find a binary chop necessary in interview questions to determine experience. e.g. when I interviewed about 30-40 "C++ programmers" one of my standard questions was "What is a virtual function?", i.e. how is a virtual function different to a regular function. I moved it further up my list over time as I found that virtually (ha) nobody knew the answer. Out of all those 'C++ programmers', I think 2 knew the answer.

      Handy though, because when I found someone who could answer it, I knew I'd found someone who had half a clue about what they're doing.

    25. Re:Slashvertisement by WeirdJohn · · Score: 1

      I have to point out that garbage collected languages have been around since a least 1976 (ST76), with major systems being developed in them from 1980 (SmallTalk-80). The issues of debugging GC languages aren't new by any means.

    26. Re:Slashvertisement by WeirdJohn · · Score: 1

      I have to disagree. I found Java a non-intuitive nightmare that dares to call itself OOP. Debugging in my experience was a shade less painful than extracting my own teeth with a set of rusty pliers. Maybe the newer Eclipse environment has changed all that, but to someone who learnt SmallTalk as their first OOP language Java is a kind of a mess. This is based on pre 2002 experience by the way - I've assiduously avoided Java since then.

    27. Re:Slashvertisement by Mr.+Shiny+And+New · · Score: 1

      so you can't do the following:

      Integer i = getIdByName(name);
      if (i == null) { // not found
      }


      or am I misunderstanding what you're saying?

      As far as I'm concerned the object wrappers for primitives are useful because they CAN be null, but this makes autounboxing more dangerous.

    28. Re:Slashvertisement by Anonymous Coward · · Score: 1, Interesting

      > VB is a poor language in many ways and not, imo, suited to a large or sophisticated project.

      What facts did you use to arrive your opinion? VB.Net now has all of syntactic capabilities of C#, and vice versa, so the language is just as suitable for any project as C#. In fact the ambiguous {} brackets and plethora semi-colons make C# code harder to read.

      VB is the Rodney Dangerfield of programming languages - it gets no respect. I've used it to produce software used by engineers/geologists that sells for minimum $25k/seat in a timeframe that easily allowed us to beat our competition to market.

    29. Re:Slashvertisement by jbplou · · Score: 1

      you weren't a vb programmer if you think VB is mainly dragging and dropping, you might be able to make some forms like that(bad forms at that). But VB.NET allows you build all levels of applications in all tiers, to any gang of 4 pattern. It is every bit the equal of C# and Java.

    30. Re:Slashvertisement by ravenlock · · Score: 1

      That's exactly what I'm saying. In C# 1.0 (up to .NET 1.1) you can't do that. In C# 2.0 you can explicitly specify you want that behavior:

      // int? is synonymous with System.Nullable<int>, the generic nullable wrapper struct for value types
      int? i = getIdByName(name);

    31. Re:Slashvertisement by nametaken · · Score: 2, Insightful


      I'm sure you're a much better programmer than I am, so I have to ask... why does using the form designer makes someone write bad database access? I'm also curious about what makes VB a poor language. I hear this pretty frequently, but have never gotten a honest explanation of why. Personally, I don't think I've ever encountered a task accomplished, or bit of code written in C# that I couldn't easily translate to VB, and vice-versa. Someone once told me there was some limitation on utilizing System.Reflection, but I just haven't encountered any problems yet. Also, don't the both compile to the same runtime language? I've always assumed it was a "6 and one half dozen" situation, and had more to do with syntax preference than anything.

    32. Re:Slashvertisement by petermgreen · · Score: 1

      We have to teach every new developer to share and reuse code and generally avoid continually reinventing the wheel
      On the other hand bringing in code from outside without understanding the license implications can also cause problems.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    33. Re:Slashvertisement by h4rm0ny · · Score: 1

      you weren't a vb programmer if you think VB is mainly dragging and dropping, you might be able to make some forms like that(bad forms at that).


      You've clearly not read my comment correctly. I didn't say that VB is mainly dragging and dropping. I quite clearly stated that dragging and dropping does not make you a programmer. What I said was that VB allows dragging and dropping without thought and that there is an industry devoted to deluding people into thinking that is all that's needed. I know this because I have had to work with (and try and educate) these people. I do not see the equivalent poverty of education in C++ because it really doesn't lend itself to ignorant people.

      I do find VB less elegant and effective than C++ which is the other language I have used significantly professionally. I've not used C#, so can't compare there. I've got non-professional experience with Java and found it better than VB, however. I'm standing by my general dislike of the language. VB's main quality seems to be a quickness and friendliness to learn. I don't see that as an advantage however, as it's not important to me in choice of language to use at this point in my career. It's lack of freedom is a separate issue but important in some circumstances. This is never shared by C++ or Java.
      --

      Aide-toi, le Ciel t'aidera - Jeanne D'Arc.
    34. Re:Slashvertisement by Anonymous Coward · · Score: 1, Interesting

      ...a good VB programmer...

      That's an oxymoron.

      If you seriously believe a VB programmer can be good, then you think a VB program can be good. You would have to reinvent VB from the ground up, as Microsoft has for the past 6 versions of VB, and you still would get a lousy language, in which serious programs can't be written.

      Even C# suffers from incompatabilities from version to version. What is it? Is Microsoft unable to create languages that are backward compatable or it does it on purpose so that companies have to rewrite their all their programs every few years?

      I think Microsoft really does it on purpose, because Microsoft has binary backward compatability for all their software (you can run DOS programs in all Windows versions, even Vista), but Microsoft prefers not to have source code backward compatability for a reason, and I guess the reason may be Developers, Developers, Developers... http://video.google.com/videoplay?docid=6304687408656696643

      They want developers to have jobs, and specially jobs that are dependent on Microsoft technologies. So you, the developer, switch to Microsoft and all your clients will always call you every few years to rewrite their very same systems. All you, the developer, need to do is to learn the little differences that spring from version to version by buying their books, so Microsoft is more a book selling company for developers, since tools are free, while at the same time, Microsoft sells cheap operating systems to companies to run the software those developers write. Microsoft has been doing this since the early 90's and it has worked well so far.

      The first problem Microsoft has is that Java is open source and Linux is open source. Any company investing on Linux and Java will never have to look back, their investment is safe. They could even run their software on Windows or AS/400 if they wish. Let's hope they don't, but let us recognize they could.

      The second problem is that source code written in Java is forwards compatable. You write now and you run it forever. Serious companies will always choose open source technologies, because they can control them (so they are safe for them) and they know they won't get buyer remorse. Is it more expensive to hire Java developers than .NET developers?

      Absolutely!!!

      http://www.indeed.com/salary?q1=java&l1=&q2=jms&l2=&q3=session+beans&l3=&q4=spring+hibernate&l4=&q5=ibatis&l5=&q6=struts+ajax&l6=&q7=j2ee+architect&l7=&q8=.net&l8=&q9=java&l9=

      So companies may think it is cheaper to build .NET apps rather than Java. They may even get away with it for a short period of time, but companies that prefer Java are more viable in the long run. And the long run is what is important when it comes to companies.

      That is what explains why developers using open source Java get rich quicker than .NET developers: Most companies have realized already about this.

    35. Re:Slashvertisement by Tablizer · · Score: 1

      VB is a poor language in many ways and not, imo, suited to a large or sophisticated project.

      It is common in custom biz apps to make several smallish apps rather than one big app. The database becomes the centralized "controller" of state, not a single massive EXE. It is often more effective to manage lots of smaller apps than one big one.

      Those who come from non-biz backgrounds seem to strive for the one big EXE approach, almost reinventing a DBMS in RAM. Java projects seem to try to do this fairly often, perhaps because promoting this behavior helped Sun sell Sun boxes when they made Java.

    36. Re:Slashvertisement by MMC+Monster · · Score: 1

      I work in a hospital with an electronic medical record that is pervasive. The entire front-end network is running WinXP.

      It's (unfortunately) not uncommon to log onto a system and one of the first windows to come up is a pop-up that tells me to hit "OK" (the only button) so that the system can do it's routine daily reboot.

      I ignore the button until I'm ready to log off. Unfortunately, sometimes I click on it before realizing it, and waste a few minutes while windows reboots.

      --
      Help! I'm a slashdot refugee.
    37. Re:Slashvertisement by Tablizer · · Score: 1

      Nah, ignore it. It's just yet another My Language Can Beat Up Your Language cat-fight, just like Chevy vs Ford fights.

    38. Re:Slashvertisement by Hal_Porter · · Score: 1

      I once worked on a hotel room booking web app that was based on ASP, components in VB and a couple in C++ and Microsoft Transaction server. There was an old mainframe guy working as a project manager that had had a meeting with Microsoft Sweden and told me "Microsoft care about this project - it is very important to them to break into the Swedish market and they won't let it fail". He insisted we all use Variants, even for the things we passed to C++ code or loop variables. Also based on his experience of ancient mainframe platforms he decided to store hotel bookings in a table like this

      Start_of_Week_Date Monday_Flag Tuesday_Flag ... Sunday_Flag

      So to book you had to find the weeks affected, check none of the flags were set and then set them. His argument was that this was faster since the database could fetch a row at a time. But it sure made the SQL atomic check for space and then book function harder to write.

      What was funny about it is that if more than about fifteen people used it it died with "ActiveX can't create object" and the webserver had to be rebooted. I left the project and worked on my own web app for the same company. I used pure ASP. My code was stable. He claimed my web app was breaking his because I hadn't complied with his coding standards and had my webapp turned off for half an hour. Needless to say his code still crashed. I don't think they ever managed to make it stable. Eventually I wrote an nasty email and they used that as an excuse to fire me.

      --
      echo -e 'global _start\n _start:\n mov eax, 2\n int 80h\n jmp _start' > a.asm; nasm a.asm -f elf; ld a.o -o a;
    39. Re:Slashvertisement by jbplou · · Score: 1

      You clearly do not understand VB it has just as much freedom as Java with the exception of only running on Windows platforms.

    40. Re:Slashvertisement by h4rm0ny · · Score: 1

      Nah, ignore it. It's just yet another My Language Can Beat Up Your Language cat-fight, just like Chevy vs Ford fights.

      You're saying that language vs. language arguments are without value. That would only be true if all languages were equal. You could say that they're useful for different purposes and that it's more useful to discuss this than to say one is better than the other. But then that's more or less what I said when I said I considered VB useful for small MS Office and little database apps, but not large projects. VB has a very fast learning curve - it's hyper friendly. That is an advantage to new programmers and not to experienced ones, which has an actual negative impact in some ways. This is what I'm saying.
      --

      Aide-toi, le Ciel t'aidera - Jeanne D'Arc.
    41. Re:Slashvertisement by Anonymous Coward · · Score: 0

      Indeed Sir!

      All of you who think desk checking is an ineffective method of debugging probably don't know what to look for!

      Those of us on the Internet for many years truly bemoaned the days when AOL, compuserve, etc. began to make it easy for people to get online.
      You see, prior to that, there was a certain barrier to entry, a minimum knowledge and intelligence level,below which you couldn' t figure out how to get online.

      It would seem that programming has gone the same way.

    42. Re:Slashvertisement by HaveNoMouth · · Score: 1
      I have to point out that garbage collected languages have been around since a least 1976...

      At least. More specifically, 1959.

    43. Re:Slashvertisement by Anonymous Coward · · Score: 0

      Like those damned lawn mower users. They think that just because they don't have to scythe each blade of grass individually they can just ignore the edges like they don't exist.

      I'm trying to think of more examples, but none really spring to mind.

      Give a moron a great tool, and he'll make a great mess. The languages don't create the coders, they'd be even worse in C++, and don't think they wouldn't still be there, they'd totally be there, and you'd totally be cleaning up after them.

    44. Re:Slashvertisement by typicallyterrific · · Score: 1

      I've never used VB or C#, but I'll venture a guess.
      The reason "VB sucks" is brandied about is mostly because database design is hard, and programming is hard, period. They are just difficult tasks to accomplish and to do both "right" requires at minimum a smidgen of talent and incredible amounts of experience.

      However, VB's syntax, dev environment and marketing makes it easier for certain people, that is, people who haven't dedicated large portions of their waking hours to programming for years, to dig in and hack something that works okay most of the time. Thus, the majority of VB code tends to be written by relatively inexperienced programmers, since us burly types all tend to stick with really masochistic languages like C++ that are less forgiving.

      So, whenever a capital P Programmer comes across most VB, her eyes will roll over, she'll throw up a little in her mouth, and then post it on worsethanfailure.com and we'll all guffaw on how most people haven't taken a course on data structures, or seem to totally misunderstand OOP, or some other fundamental concept. Thus, VB has a bad rap.

      In reality, there is no limitation to what you can do in VB. It's a language, a Turing complete one at that, and thus by definition (google Turing-Church hypothesis) anything you can describe in C# you can similarly describe in VB. Whether or not the implementation of the language or underlying hardware will limit you or not, is a different story.

    45. Re:Slashvertisement by Anonymous Coward · · Score: 0

      Almost without exception when you see one of these "VB sucks" opinions, you can assume it's referring to classic VB (VB6 or earlier, or perhaps VBA) unless VB.Net is explicitly stated. A number of other posters have already stated that VB.Net provides the same capabilities as C#, and that is essentially correct. But if you had ever moved from some "modern" language such as C++ or Java (or even a tenacious older language like LISP) to classic VB, even for only 8 months, you'd have an appreciation for h4rm0ny's post. I've done way more classic VB/VBA programming than h4rm0ny is willing to admit to, and my experiences accord strongly with his assertions. There's more utter crap VB/VBA code out there than most people realize, and not much of it is likely to be ported to VB.Net any time soon, if ever - I bet most of it will end up being maintained well beyond obsolescence. One need not be some kind of uber-coder to recognize these problems.

      If you find someone bashing VB.Net explicitly in contrast to C#, then it's usually someone who has assumed VB.Net retained the deficiencies of classic VB, or they're a syntax weenie, or maybe they're just trolling. Again, those are my experiences.

      - T

    46. Re:Slashvertisement by bensch128 · · Score: 1

      Really?
      After doing some research for a decent windows profile, the only manually controlled M$ profiler is only available in their very expensive team edition.

      The one which does the automatic reordering of ops doesn't count because it doesnt actually show the user ANYTHING!

      Ben

  4. Friends do not let Friends use Windows and Drive by WindBourne · · Score: 0, Troll

    There is your problem. Quit using systems that yield blue screams of death (literally).

    --
    I prefer the "u" in honour as it seems to be missing these days.
  5. Stupid Slashdot headline by RzUpAnmsCwrds · · Score: 5, Interesting

    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.

    1. Re:Stupid Slashdot headline by dgun · · Score: 3, Interesting

      Maybe so. But if they explicitly call delete to invoke the garbage collection of an object, would it not be better for the system to destroy the object and then throw an exception when it tried to send an event notification to a non-existing object?

      Furthermore, if delete is called and the garbage collector does not delete the object because it realizes that the object is registered on certain events, would it not be just as easy to then un-register the object for the event? Or at least report it? After all, the GC already went to the trouble of checking to see if the object was registered with an event notification.

      --
      FAQs are evil.
    2. Re:Stupid Slashdot headline by MathFox · · Score: 3, Insightful
      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.

      --
      extern warranty;
      main()
      {
      (void)warranty;
      }
    3. Re:Stupid Slashdot headline by cnettel · · Score: 4, Interesting

      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.)

    4. Re:Stupid Slashdot headline by blowdart · · Score: 5, Insightful

      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.

    5. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0

      Hence the explicit part. TBQH something can probably be hacked together in .net 2.0 w/ reflection etc. to "make" the GC delete an object, even if you can't remember if it's subscribed to any events..

    6. Re:Stupid Slashdot headline by slashdot.org · · Score: 5, Insightful

      Of course you can have a memory leak in a managed language! Any Java programmer who's decent understands that.

      Decent programmers might understand that, but let's be honest, it's not like Java (and other GC languages) haven't been presented as if memory leaks were a thing of the past.

      As a matter of fact, some people will probably still claim that it's technically not a memory leak, but instead an object life-span issue.

      What surprises me is that outspoken proponents of managed languages use the garbage collection so often as a good thing, as if now you can be a sloppier programmer and get away with it.

      In reality you have to identify/control the lifespan of objects anyway, so I personally never understood what the big deal is about freeing memory manually. Not to mention that memory leaks in say, C++ code, really aren't that hard to find. The tools have become pretty freakin decent.

      And also not to mention that garbage collection might be handy for memory, but memory is only one of a plethora of resources that can be leaked. And since for many resources it isn't nearly as appropriate to 'lazy' free them, as a programmer you still have to be aware of the allocate/free paradigm. (as just one silly example, it would suck if you wouldn't be able to explicitly close a file, because you can't delete it before it's closed)

      In other words, you are right. Of course you can have memory leaks in garbage collected languages. And I wish people would stop using GC as an argument why languages as Java are so much better to use than C++.

    7. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0

      Quite... imagine my disappointment when reading an article whose title suggests every mug using C# is going to get hit with a problem they have no control over and no way to fix whereas in fact it's just a classic programming error in a single app. It's like y2k all over again for me. No flames, no explosions, just one lousy program telling me the year is 19100.

      One interesting facet to this, though, is that although GC languages are touted as safer, the consequences can be just as dire as others; here you have a potentially life-threatening machine running about without much control because it's getting slower and slower either because it's started paging or just got to traverse so many references each time it has to make a decision. No fail-safe kicks in because everything's working and so this alzheimer's death machine winds up running people over after 40 minutes of operation.

      Compare the equivalent in C/C++: the programmer explicitly frees the memory and as soon as the object is referenced after the program is killed. Failsafes then kick in so you don't have a bunch of students running after a rogue machine trying to pull the plug whilst avoiding its twin anti-aircraft cannons or whatever.

    8. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0

      I agree. It's ridiculous how the summary tries to spin this so it seems like a C# bug.

      But it turns out it was a bug in an application which happened to be written in C#. The garbage collector worked as advertised. If an object can still be accessed (in this case through an event handler) then it cannot be garbage collected (even if the event handler isn't actually called). It's unfortunate if Princeton's students didn't realize this, and I'm sorry for them, but in no way is this a bug in C#. A program written in Java would exhibit the same behaviour.

      In contrast, thousands of applications written in C and C++ contain memory leaks. They never make the headlines. It may be a surprise to some naive programmers who think that a garbage collector could solve all their memory bugs, and even if this is an interesting case study, I do not think it qualifies as "news".

    9. Re:Stupid Slashdot headline by nwbvt · · Score: 1

      Just because garbage collection doesn't prevent memory leaks doesn't mean that it isn't a good thing. It does make them harder to create. And given the level of skill the average programmer has, anything that makes memory leaks less likely (though not impossible) has got to be seen as a good thing.

      --
      Mathematics is made of 50 percent formulas, 50 percent proofs, and 50 percent imagination.
    10. Re:Stupid Slashdot headline by multi+io · · Score: 3, Insightful

      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.

    11. Re:Stupid Slashdot headline by OrangeTide · · Score: 1

      Of course there are hundreds of tools available commercially and for free that can trace and detect the tiniest memory leaks in C/C++. Good unit tests help as well, especially if you can model a theoretical run before putting the entire thing together.

      --
      “Common sense is not so common.” — Voltaire
    12. Re:Stupid Slashdot headline by rbanffy · · Score: 1

      The proper way to do it would be a "getRidOfMyself" method that notified all its subscribers that the subscribed object is going to be deleted and should no longer be referenced. It's nothing the GC could or should do and making the GC "delete-no-matter-what" option available is bad design practice because it allows an incorrect program to behave like a correct one.

    13. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0

      OK then, *you* try writing some decent embedded real-time software in a GC language when the GC can randomly eat up almost your entire frame time, leaving you no time to do the processing you need to do for that frame. Or even worse, when the GC takes up MORE than one frame.

    14. Re:Stupid Slashdot headline by PhrostyMcByte · · Score: 1

      And I wish people would stop using GC as an argument why languages as Java are so much better to use than C++.

      As a C++ developer, GC is the main thing that turns me off to so many languages. With C++ I know exactly when objects will be destroyed - with C# I have no clue, leading to silly stuff like "using" and "try...finally" to make sure that file/socket/etc. is closed. Java/C# proponents always point to memory leaks as a reason for GC, but C++ makes it mind-numbingly easy to avoid them. You do not usually need to use pointers that often, but when you do smart pointers can help manage lifetime without any overhead.

    15. Re:Stupid Slashdot headline by __aasmho4525 · · Score: 1

      your solution is absolutely the correct way to do this.

      works perfectly in clr.

      cheers.

      Peter

    16. Re:Stupid Slashdot headline by Zebra_X · · Score: 1

      The safety of this machine had nothing to do with the programming and everything to do with the creators who failed to test their system sufficiently.

    17. Re:Stupid Slashdot headline by Jugalator · · Score: 1

      True, the closest you'll get to a C# "delete" is calling the object's Dispose() method, or by using the "using" construct as in:

      using (StreamWriter writer = new StreamWriter(filePath))
      {
              writer.Write("Blah");
              writer.Close();
      }


      The writer object can now not be used after the using block, and you inform the compiler that it can be safely garbage collected immediately after use.

      Still, there's no guarantee in C#, and some other languages like this, that it'll be immediately gc'ed as with delete, because the garbage collector is non-deterministic.

      --
      Beware: In C++, your friends can see your privates!
    18. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0
      StreamWriter.Dispose() will also flush and close the stream, so the above can also be written as:


      using (StreamWriter writer = new StreamWriter(filePath)) {
      writer.Write("Blah");
      }

    19. Re:Stupid Slashdot headline by mrwolf007 · · Score: 1

      Decent programmers might understand that, but let's be honest, it's not like Java (and other GC languages) haven't been presented as if memory leaks were a thing of the past. As a matter of fact, some people will probably still claim that it's technically not a memory leak, but instead an object life-span issue.
      Then do please tell me how you define a memory leak.
      How about a simple: Memory that was allocated and is no longer referenced.
      Unless you have a different definition there are no memory leaks in Java, or C# for that matter.
      Obviously the objects mentioned were still referenced. Its a simple bug in their code, not a memory leak.
    20. Re:Stupid Slashdot headline by minniger · · Score: 1

      Unfortunately parent and the parent-parent have clearly never actually written anything of significance with a GC language. Using and try-finally have little to do with GC btw.

      You can program sloppily in any language. If you knew exactly when objects were destroyed in C++ you'd never need a profiler. Clearly this is not the case for any non-trivial application (is sure as hell isn't mind-numbingly easy). Are you seriously saying smart pointers are easier to use than built in GC?

      The advantage of GC languages is that for most cases you simply don't have to worry about memory management. It's a whole class of problems you just don't deal with. Sure, there are corner cases that'll get you, but once your familiar with them you can usually avoid them. And those corner cases require a lot less effort to avoid then all the various ways you can screw things up in C++. GC tech is pretty mature and while it's not suited to everything you've got yourself a big hill to climb if you want to argue that manual memory management will result in less buggy programs than GC.

      Now I'm going to go read TFA...

    21. Re:Stupid Slashdot headline by gbjbaanb · · Score: 3, Insightful

      And given the level of skill the average programmer has, anything that makes memory leaks less likely (though not impossible) has got to be seen as a good thing. NO! It is not a good thing, if a program slowly leaks memory then it just makes it harder to find the bug. If you have to reboot the app every week because it has a little leak, no-one's going to be bothered (except the users who see it slowly getting slower). If it has to be restarted daily then you're going to be looking to fix the bug.

      It is easy to leak memory in C++, if you don't know what you're doing. Its easy to leak memory in C#/Java if you don't know what you're doing. That the language makes it easy for you to avoid becoming a better programmer is NOT a good thing.

      I have a good analogy - Firefox. I use FF a lot, I like it, but it does tend to increase its memory usage over time, and has been rightly criticised for it. Now, I'm sure the 'bug' is an aspect of its design and not a programming bug (and I don't want to start a FF memory discussion - I'm only using it as a real-world example) but just imagine if *every* program was like FF - slowly using more and more RAM over time until you restarted it.

      This is what you're asking for when you say that its ok for the average programmer to use C# because the app will have fewer leaks: you'll get fewer leaks. Not none. If the app leaked like a sieve, it'd be spotted in development/test and fixed; if it leaks slowly enough so it passes an hour's testing in certification, then it'll be shipped - and its you that'll get to find the bug as you use it.
    22. Re:Stupid Slashdot headline by minniger · · Score: 1

      TFA is a FAdvert...

      Still, their bug had nothing to do with GC and everything to do with a programming error that would have happened in any lang. I suppose you could argue that if they had used C++ they'd have found it due to running a profiler in the first place. But I'm not sure that's a positive one...

      Hum... the whole thing kinda makes you wonder why they didn't profile it a long time ago anyway... but we've all done something similar at some point.

    23. Re:Stupid Slashdot headline by __aamnbm3774 · · Score: 0

      ummm no...

      There are several popular ways to achieve deterministic memory deallocation in C#.
      Calling *.Dispose or put your objects inside a using block for starters.

      The programming skills of the team is under question, not C# and .Net

    24. Re:Stupid Slashdot headline by Mr.+Shiny+And+New · · Score: 4, Interesting

      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.

    25. Re:Stupid Slashdot headline by feronti · · Score: 1

      That's what deterministic garbage collectors like IBM's Metronome are for. Real-time programmers really should start reading... it seems none of the embedded people I've talked to have any idea what kind of research is being done in their own field. Though I guess the same could be said of all programmers, really. It's kind of sad.

    26. Re:Stupid Slashdot headline by luzr · · Score: 1

      Unfortunately parent and the parent-parent have clearly never actually written anything of significance with a GC language. Using and try-finally have little to do with GC btw. Wrong, it has everything to do with GC. GC is mutually exclusive with concept of destructors, therefore GC collected language needs other means than scope based destruction to free resources in case of exception. That is why Java has "finally" and C++ not.

    27. Re:Stupid Slashdot headline by psmears · · Score: 1

      In reality you have to identify/control the lifespan of objects anyway, so I personally never understood what the big deal is about freeing memory manually. Not to mention that memory leaks in say, C++ code, really aren't that hard to find. The tools have become pretty freakin decent.

      I agree with you that GC has been presented as a cure for all memory leaks, and that a lot of not-very-clueful people think that you can get away with being sloppy; however I do thing that GC is a good thing: there are several problems directly related to manual allocation and freeing of memory, including:

      1. Forgetting to initialise a pointer (access to random memory)
      2. Attempting to access via a null reference (null pointer)
      3. Forgetting to free memory (memory leak)
      4. Freeing already freed memory (double free)
      5. Accessing already freed memory (memory scribble)

      Of those problems, the first can be solved without GC (by forcing/checking for initialisation), and the second at least results in a clean runtime exception.

      Of the others, the double-free and memory-scribble are notoriously hard to debug, since they typically result in unpredictable behaviour that may be completely unrelated to the original problem—but GC eliminates these entirely (or at worst transforms them to memory leaks).

      Ironically, given all the rhetoric, the one problem that GC doesn't eliminate (other than in relatively simple cases) is the memory leak :-). But then—as you say, it's plenty possible to provide good tools to detect and debug that sort of problem.

    28. Re:Stupid Slashdot headline by psmears · · Score: 1

      Then do please tell me how you define a memory leak.

      Simple, memory that has been allocated, is no longer needed, but will never be freed.

      Unless you have a different definition there are no memory leaks in Java, or C# for that matter. Obviously the objects mentioned were still referenced. Its a simple bug in their code, not a memory leak.

      That's just silly. A memory leak is a simple bug in the code—saying that "all unused memory will definitely always be freed (oh, provided there are no bugs in the code)" is true whether you have a garbage collector or not :-)

    29. Re:Stupid Slashdot headline by maraist · · Score: 1

      C/C++ have stack-variables, and I agree, there's nothing more memory efficient than this. Allocation/De-allocation rivals even the performance of a copying-collector's malloc, since you aggregate several allocations in a single stack-pointer increment with compile-time offsets into the memory frame. But it's VERY hard to write generalized code that takes in pointers, and still avoid memory leaks (or in this worse case, stale pointer references)..

      To guarantee no memory leaks/stale-pointer-references, you have to
      A) NEVER keep a cached reference to any passed in pointers, which limits the types of algorithms available to you, as well as the performance possibilities.
      B) NEVER link one object graph to another (as you've affectively just cached references as in A)
      C) NEVER allocate new memory and attach it to the input object graphs.

      Doing any of the above would violate good defensive programming practices - you would be relying on the caller to properly maintain your memory, or to keep your memory references alive. This is not to say that you CANT do these things.. But you must have faith in God and your partner coder that they're not going to miss the fact that they have to manage your memory.

      Both with C++ and in reference-counted memory managers (like perl), you have the additional problem of circular references. C++ has the advantage of knowing that a doublely-linked list should all be freed at once. But the generalized problem still exists.. If class A has a bi-directional reference with class B (which is generally bad coding practice), then in which order can you safely destruct? The destructor of B might dereference A and thus access corrupted memory.. (since traditional malloc overwrites the allocated memory to store free-list pointers).

      While A B is generally bad. In symmetric code, this is usually pretty common (parent/child relationships for example) and thus a necessary, but managed evil. But the key is when you generalize the relationship enough such that you have indirect cycles. Say A has a cache of objects which can hold something that ultimately points back to A.

      You simply can't handle this sort of object-graph traversal w/o dynamic memory. And cycle-management MUST be explicitly maintained.. This maintanance is a programming-contract/policy-contract. Once you share this code with outsiders, that contract is free to be violated (due to lack of understanding or too quick of a reading).

      C++ forces you to become an expert in the shared library module. But in languages that have strictness in programming safety - especially those with pre-defined generalized APIs that are trivial to conform to (Maps, IO, Transfomers, etc), then you need only become an expert in the generalized API, while still being able to handle a LARGE variety of coding interconnections with minimal coding/memory concerns. The lesser the impedance mismatch between two APIs, the greater the synergy. In Perl, all functions use dynamically resizable reference-stacks. In Java absolutely everything can be an Object (though primitives auto-boxing wasn't until JDK 1.5), and thus used by any generalized IO/Data-type/Transformer. And with zero concern about memory leaks. I think Lisp just uses the same-size memory objects for everything.

      Granted, explicit caching is still a concern. Especially for idiots that still use static variables (both in Perl and Java) - We're in the inversion-of-control era for God's sake.

      In a GC environment, you are MOSTLY free to avoid memory allocation and thus GC pausing.. Use inversion-of-control to pre-allocate all of your domain/model/service classes. Keep references to the model object graphs in the worker threads main loops. Reuse thread-safe static references to large byte-arrays (such as StringBuilders, ArrayLists, etc). The transient references that 3'rd party libraries instantiate should be trivial to GC, as your semi-permanent objects will quickly be tenured. So long as there are few static variables, and you have only a f

      --
      -Michael
    30. Re:Stupid Slashdot headline by naasking · · Score: 1

      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.

      Pardon the analogy, but there's a big difference shooting yourself in the foot with a shotgun and a bb gun; 9.999 times out of 10, your foot will survive a shot from a bb gun.

    31. Re:Stupid Slashdot headline by naasking · · Score: 1

      NO! It is not a good thing, if a program slowly leaks memory then it just makes it harder to find the bug. If you have to reboot the app every week because it has a little leak, no-one's going to be bothered (except the users who see it slowly getting slower).

      This implies the language is lacking something, not that automatic memory management is a poorer choice than manual memory management. In this case, the language lacks facilities to book memory to executing agents (like a lightweight language process), and to recover from failures, ie. kill and restart the language process running the application (see Erlang for instance). Now you have your automatic memory management, AND your automatic failure recovery.

    32. Re:Stupid Slashdot headline by naasking · · Score: 1

      What surprises me is that outspoken proponents of managed languages use the garbage collection so often as a good thing, as if now you can be a sloppier programmer and get away with it.

      No, it lets you become a *better* programmer because the focus is now on the algorithms, instead of cluttered with resource management issues.

      In reality you have to identify/control the lifespan of objects anyway, so I personally never understood what the big deal is about freeing memory manually.

      With respect, you will probably never understand the big deal until you work in a more advanced language such as Haskell or OCaml. The fact is, you often *don't* have to manage resource lifetimes, and the advantages of automatic memory management become *very* apparent when you work in fine-grained compositional languages, rather than coarse-grained imperative languages.

      And since for many resources it isn't nearly as appropriate to 'lazy' free them, as a programmer you still have to be aware of the allocate/free paradigm.

      I've heard this trumpeted may times, but it's a fallacy. Memory is a fine-grained resource whose lifetime is error-prone and tedious to manage. Coarse-grained resources such as file handles or sockets are easier to manage, and their lifetimes are part of the semantics of their interface (although Java and C# do a very poor job of specifying these semantics in their interfaces).

      I would totally agree with you that manual memory management was good if it had a proper formal semantics which prevented you from freeing memory early. In fact, such languages have been built. C/C++ is not one of them.

      I wish people would stop using GC as an argument why languages as Java are so much better to use than C++.

      Seriously! There are so many other reasons, why focus on just the one! ;-)

    33. Re:Stupid Slashdot headline by naasking · · Score: 1

      You do not usually need to use pointers that often, but when you do smart pointers can help manage lifetime without any overhead.

      I could chalk your post up to a matter of opinion right up until I hit this point. Fact is, smart pointers ARE an incremental garbage collection technique called reference counting. In fact, it's now well known that all garbage collectors are a hybrid between incremental reference counting techniques and stop-the-world tracing techniques.

    34. Re:Stupid Slashdot headline by naasking · · Score: 1

      C/C++ have stack-variables, and I agree, there's nothing more memory efficient than this.

      Region-based memory management (also sometimes known as arenas in the C/C++ world) is at least as efficient, and strictly more general than stack allocation.

    35. Re:Stupid Slashdot headline by 12357bd · · Score: 1

      Absolutely correct.
      Programming physical machines/factories/objects is a very interesting ambient. When your (or someone else) mistake correlates (or have the potential to) to physically damaging people you'll get a new sense of what a 'programming error' is.

      --
      What's in a sig?
    36. Re:Stupid Slashdot headline by Rimwolf · · Score: 1

      I personally never understood what the big deal is about freeing memory manually.


      The really big deal is that if you ever free a single object/allocation while there's another reference to it, you've created a timebomb. This kind of problem is excruciatingly hard to debug when the memory gets reallocated.

      The big deal is that if you do enough bookkeeping to guarantee that you never free referenced memory, and you have objects with nontrivial lifetimes, then you've spent a great deal of time writing a memory management system that's not as good as what's built into any modern language.
    37. Re:Stupid Slashdot headline by PhrostyMcByte · · Score: 1

      think of scoped_ptr and auto_ptr. no reference counting there. shared_ptr may get a bulk of the talk, but it's not the only smart pointer out there (and certainly shouldn't be used as an app-wide garbage collection).

    38. Re:Stupid Slashdot headline by Mutatis+Mutandis · · Score: 1

      In reality you have to identify/control the lifespan of objects anyway, so I personally never understood what the big deal is about freeing memory manually.

      Many, maybe even most, objects of which you would handle the lifespan manually in a Java application, are resources that exist on a single thread. Dialogs and various I/O objects, for example. And yes, I've also made the mistake of giving a dialog a reference to 30 Mb of data, and then forgetting to dispose of the dialog (instead of only closing it). Mistakes do happen. Nevertheless managing objects on a single thread is relatively easy and involves little overhead.

      But the objects that are shared between different threads are very often the kind that can be safely left to the GC to handle. Of course, you can exchange objects between different threads in C++ and still manage the memory, but frequently enough you'll find yourself incrementing and decrementing references all over the place, adding management code and complexity. Or you have to rely on libraries that do it for you, but impose limitations that completely mess up your neat design. If there is a GC that can accurately figure out whether an object is referenced or not, that saves a fair amount of coding in a multi-threaded application, and eliminates hard-to-debug errors. It also simplifies the design.

      Yes, there may be resources that are shared between threads and cannot be left to the garbage collector to properly clean up. Database connections, for example. But it's less costly to handle a few objects manually, than all of them. And for a single-threaded piece of code there may indeed be little to choose between GC and manual memory management; the latter is likely to be a bit more efficient. But how many serious applications are really single-threaded these days?

      I admit that I have enough C++ background to feel uncomfortable, from time to time, with the idea of allowing the GC to handle things. You wonder what the lifespan of an object will be, and have no sense of closure. But actually, often enough not worrying about things is the right solution.

    39. Re:Stupid Slashdot headline by naasking · · Score: 1

      auto_ptr have scoped lifetimes; in other words, no better than stack-allocated objects. scoped_ptr doesn't seem much better than manual memory management, except for its use of RAII which prevents uninitialized use.

    40. Re:Stupid Slashdot headline by cryptoluddite · · Score: 1

      As a matter of fact, some people will probably still claim that it's technically not a memory leak, but instead an object life-span issue. That's because it's not a memory leak, it's just memory not being released at the moment. A classical leak is never released and can't be accessed on purpose. In Java or other garbage collected languages your code may hold onto references when it does not need to, but these will eventually be reclaimed... when the function is finished, when the next 'page' is rendered, when the race is completed, or finally when the program is terminated if finalizers are run on exit.

      What surprises me is that outspoken proponents of managed languages use the garbage collection so often as a good thing, as if now you can be a sloppier programmer and get away with it. Garbage collection makes a lot of memory management easier, not 'sloppier'. Take for instance in C releasing an object from a callback issued by that object. You can't just 'free' the object since you are in a call stack within the object's own functions... maybe the object can guarantee not accessing itself after your callback completes but this is not always possible and always complicated. Instead, you often have to 'schedule' your object to be actually freed at some later time. With GC you typically just unreference the object.
    41. Re:Stupid Slashdot headline by HeroreV · · Score: 1

      That the language makes it easy for you to avoid becoming a better programmer is NOT a good thing. Using a more difficult language doesn't make people better programmers. If that were true, we'd all be coding in assembly. Do you code everything in assembly? If you practice what you preach you would.

      I don't want to start a FF memory discussion Too bad, I'm doing it anyway, because it's a great example. Firefox's memory leaks are negligible, the real problem is fragmentation. And you know what would fix that? A moving garbage collector. You'd be seeing lower memory usage if Firefox was using a garbage collector.
    42. Re:Stupid Slashdot headline by mpeg4codec · · Score: 1

      as just one silly example, it would suck if you wouldn't be able to explicitly close a file, because you can't delete it before it's closed
      Just to nitpick, I've never seen this problem on any modern operating system I've used. On the Unix-like ones, calling unlink on a file name will remove that file from the file system. If any process still has open descriptors for it, the data will be retained until those are freed by manually calling close or when the process exits.

      I suppose this could lead to a problem if one has a long running process holding onto descriptors for huge files, but you seem to imply that they'll be freed eventually anyway. Anyway I don't mean to troll, just have nothing better to do on a saturday morning than nitpick!
    43. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0

      As a matter of fact, some people will probably still claim that it's technically not a memory leak, but instead an object life-span issue. I guess they are the same folks who like to label some ducks swan, geese or pigeons..
    44. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0

      Garbage Collectors also make it very difficult to state precise upper bounds on the execution time of a particular block of code - when will it decide to cycle, halting execution? Surely a fundamental requirement for a real time system such as this (e.g. guaranteed to take evasive action within x ms of sighting advancing tree). Or indeed to formally prove that your code is correct, arguably vital for some systems.

      The C# GC can be postponed, but ultimately in a real time system there would be no "safe" time in which it could be told to catch up. Amortized allocation is only half the solution, and indeed the efficiency of some I/O bound algorithms depend upon manual memory management.

    45. Re:Stupid Slashdot headline by CodeMunch · · Score: 1

      But if they explicitly call delete to invoke the garbage collection of an object, would it not be better for the system to destroy the object and then throw an exception when it tried to send an event notification to a non-existing object?
      No, it would not be best to actually delete the object that has an existing reference. That would be called data loss. When you subscribe (+=) to an event it generally means you want to know stuff about it. If you don't want to know stuff about it anymore, then unsubscribe (-=). The first time I implemented custom events in C# I made the exact same mistake. However, it only took a little bit of testing to find that I had "ghost" objects hanging around. This "leak" (behaviour) should have been found in even the smallest amount of testing.

      I wouldn't want to trap an error every time the GC checked to see if it could free up some memory.

      would it not be just as easy to then un-register the object for the event?
      Yes, it is as easy as "-=".

      Or at least report it? After all, the GC already went to the trouble of checking to see if the object was registered with an event notification

      That would be making huge assumptions. You have a reference to an instance of an object. How would a GC know that the object isn't supposed to hang around and continue doing it's task when the calling object's event fires.

      In any case, this was a great learning experience for them and you could almost guarantee that in any future endeavours that they'll never overlook this

    46. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0
      Princeton's "obstacle object" lifetime policy was most definitely NOT stepped upon by a .net Library.

      For the Princeton car software, an explicit deallocation routine (like in C/C++) would have been easy to implement
      It was also easy to implement in C#: by unhooking the event.

      Face it, these guys had a bug. A trivial bug, at that, and one that would have existed any any language on any platform where they made the same programming error.
    47. Re:Stupid Slashdot headline by porpnorber · · Score: 3, Interesting

      I must apologise in advance if this is a bit of a rant. I have a graduate degree in, well, programming language design, and I find some things close to my field just very upsetting. You wrote:

      "...let's be honest, it's not like Java (and other GC languages) haven't been presented as if memory leaks were a thing of the past.

      "As a matter of fact, some people will probably still claim that it's technically not a memory leak, but instead an object life-span issue.

      "What surprises me is that outspoken proponents of managed languages use the garbage collection so often as a good thing, as if now you can be a sloppier programmer and get away with it.

      "In reality you have to identify/control the lifespan of objects anyway, so I personally never understood what the big deal is about freeing memory manually. Not to mention that memory leaks in say, C++ code, really aren't that hard to find. The tools have become pretty freakin decent."

      Perhaps you write very C++-adapted, boilerplate code. The reason garbage collection is essential in a programming language is that without it (a) you cannot provide a safe implementation of first-class functions, since they implicitly grant indefinite lifespan to arbitrary objects; and (b) you cannot build an abstract data type, whose implementation is hidden from the user, since no matter what other features the language may have, you can always tell whether the type a library has handed you is an automatically managed 'atomic' object, or a 'reference type.'

      But why get so upset about weird advanced programming techniques not coming out quite right?

      Because the kicker is, that to those of us who grew up with garbage collected languages, first class functions and abstract data types are elementary programming techniques. They are the bricks and mortar of which everything else is made. "Data structures + Algorithms," you see. Sure, C++ programmers consider it rocket science and discuss ad nauseum their clever smart pointer techniques and their baroque fifty-line function object implementations (or, if they advocate Boost, their two line function object implementation that requires a five thousand line header file and employs a completely different syntax from everything else they do). That's because they're now used to getting through life with no arms and artificial legs.

      The sense in which garbage collected languages make memory leaks a thing of the past is this: that if you received a non-C++-adapted education, focussed on data structures and algorithms and not the fifty-three (or five thousand and six - they make money, let's invent more) Programming Patterns that help you evade the design flaws of the One True Language, and so you are in the habit of thinking and coding using callbacks, strategy functions, abstract types, state encapsulators - all those basic things that (unless the goal is avoiding the shortcomings of C++) are taught in school, and, indeed, all those things that both functional programming and object oriented programming were invented to make notationally direct, then you can just go ahead and code what you think, and you won't be bitten on the bum. The abstract model of computation comes reasonably close to matching the reality. Without it, you're still tracing through the execution in your mind at every step, because relying on the abstraction itself will get you burned.

      Yes, a competent programmer can adapt. Yes, a competent programmer can think at the level of assembly language and either work out exactly the lifetime of the data, or do a second explicit computation, woven in with the main one, to determine it dynamically. A competent programmer can also deal with a language having divergent notations for data, expressions, statements, type expressions, templates, and type expressions within templates; or to phase of the moon dependent name resolution (templates again!); or to notational 'abstractions' requiring manual instantiation in real implementati

    48. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0

      "as just one silly example, it would suck if you wouldn't be able to explicitly close a file, because you can't delete it before it's closed" ...on Windows. On less shitty operating systems with less shitty filesystems, you can safely delete a file before closing it. This will prevent it from being opened by anything else, and the filesystem will deallocate the space when it is closed.

    49. Re:Stupid Slashdot headline by isntwargreat · · Score: 1

      Whatever; it's idiotic to think that garbage collection means no memory leaks. GC cleans up the program when it ends, and objects get deleted if there are no outstanding references to them. In this case, there were outstanding references to the objects. I can't believe that there is even a widespread difference of opinion on an issue like this...

    50. Re:Stupid Slashdot headline by dgun · · Score: 1

      Whilst that would remove the object from the collection itself it is *not* a delete.

      Oh, I see. The article made me think they were requesting the GC to delete the object. I have not used C#, so I was relating to something similar in Java.

      --
      FAQs are evil.
    51. Re:Stupid Slashdot headline by tepples · · Score: 1

      What about these other issues?

      6. Memory from freed or collected objects being broken into chunks too small for allocating more objects (heap fragmentation)
      7. Semantics of popular languages (such as C++) making it difficult for a precise collector to work, forcing third-party garbage collection libraries such as Boehm's to adopt a conservative strategy that confuses some non-pointer bit patterns with pointers to live objects
      8. Resources other than memory that need to be collected
      9. Real-time collectors not being provided as standard equipment in affordable compiler toolchains for your language and platform

    52. Re:Stupid Slashdot headline by ir · · Score: 0

      just use valgrind, and you can stomp out these problems quickly.

      the main failure of C++ is its limited standard library (e.g. no network sockets)

      --
      Irina Romanov
    53. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0

      hey smartass, what do you think yer fancy ultra-high level language is compiled down to? hows about programmers work with the _simple_procedural_machine_ they are operating, instead of pretending it's some kind of whiz bang math abstraction...

    54. Re:Stupid Slashdot headline by tepples · · Score: 1

      A classical leak is never released and can't be accessed on purpose. In Java or other garbage collected languages your code may hold onto references when it does not need to, but these will eventually be reclaimed [...] when the program is terminated How does this differ from the malloc/free model, in which the operating system destroys all arenas when the program exits? Under this definition of leak that considers memory collected only at program termination to not have been leaked, there is no such thing as a leak in any model.
    55. Re:Stupid Slashdot headline by mrwolf007 · · Score: 1

      That's just silly. A memory leak is a simple bug in the code--saying that "all unused memory will definitely always be freed (oh, provided there are no bugs in the code)" is true whether you have a garbage collector or not :-) Sorry, you are just silly.
      If the memory is unused (no longer referenced) it will be freed.
      And, dont get me wrong, im more into c and c++ currently (the help java used to provide me actually seems somewhat constraining), but nonetheless i cant deny their use.
      Its definatly as bad as basic, and definataly hasnt the power of pure C (or C++) but its pretty useful (talking about java here, but pretty much the same applies to C# from a pure language perspective).
    56. Re:Stupid Slashdot headline by mrwolf007 · · Score: 1
      This discussiom is GETTING SILLY.

      That's just silly. A memory leak is a simple bug in the code--saying that "all unused memory will definitely always be freed (oh, provided there are no bugs in the code)" is true whether you have a garbage collector or not :-) IT IS NOT UNUSED!!!!
      Sorry, but just how stupid are you guys???
      If it where unused (no longer referenced) it would have been cleened up.
      I dont like Java all too much (even if i did get some Certs there) but this i REDICOULUS BULLSHIT. Amen
    57. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0

      >(as just one silly example, it would suck if you wouldn't be able to explicitly close a file, because you can't delete it before it's closed)

      Believe it or not, this is the problem with Windows - you can't delete open files. (Try nuking C:\windows and you get a showstopper soon.)

    58. Re:Stupid Slashdot headline by cakoose · · Score: 1

      In other words, you are right. Of course you can have memory leaks in garbage collected languages. And I wish people would stop using GC as an argument why languages as Java are so much better to use than C

      Yes, the headline is stupid and you can leak memory in garbage-collected languages.

      However, I do really think that garbage collection makes a huge difference in programmer productivity. Just because it doesn't solve every resource problem doesn't mean it's useless.

    59. Re:Stupid Slashdot headline by Rimwolf · · Score: 1

      Try googling for "realtime garbage collector": there's been a lot of work on this for at least a decade or two, which addresses precisely the problems you mention.

    60. Re:Stupid Slashdot headline by petermgreen · · Score: 1

      now try running on NFS and removing not just the file but it's containing folder as well. Suddenly things stop working.

      And that is in the *nix world, in the windows world (which can't be ignored by most of us) things are much worse.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    61. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0

      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.


      I'm glad to see this mess being finally explained in Slashdot. I have been myself contradicting Java developers on this same issue for years and since most Java developers have never used C++, they really can't understand what is it like to have real memory leaks, dangling pointers and the like.

      I think this change is for good. Having better languages with less problems is always welcome. What I dislike is that a different problem gets an old name. Overloading should be reserved for computer languages only.

    62. Re:Stupid Slashdot headline by madcow_bg · · Score: 1

      Yeah, you're right!!! More to the point, if you are smart and want to use pointers in C++, maybe use the concept of smart pointers. It is still faster and you take advantage of C++'s most unnoticed feature - that a destructor of a local object is called even when traversing the stack by the exception. It is EASY to write good code, just do practice, god dammit!!! Read! Think! My worst problem with java is the unresponsive interface. The GC seems to be is always called when the menu is supposed to pop-up instantly!? Fuck it, why not just use C++. (Unfortunately I am stuck with Delphi in my work, so I'm screwed...)

    63. Re:Stupid Slashdot headline by minniger · · Score: 1

      Er... you need to read up on exception handling in Java... GC is about scope/reachability... try-finally is about exception handling. Exiting a finally MAY cause things to go out of scope and be available for GC.. or may not. In GC languages destructors don't really exist (finalize is kinda/sorta like one) so I suppose that is pretty mutually exclusive.

      C++ doesn't have a finally since resources used by a class should be freed by the class in the destructor. Assuming you call the destructor then things will get cleaned up.

      I'm not saying there's anything wrong with the parent posters knowledge of C++... rather they are bagging on GC when their arguments make it appear that they don't really know much about GC languages.

    64. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0

      I'd be content with force delete and slaughter the heap if a pointer referencing it is ever used.

    65. Re:Stupid Slashdot headline by nwbvt · · Score: 3, Informative

      "NO! It is not a good thing, if a program slowly leaks memory then it just makes it harder to find the bug. If you have to reboot the app every week because it has a little leak, no-one's going to be bothered (except the users who see it slowly getting slower). If it has to be restarted daily then you're going to be looking to fix the bug."

      Actually the good companies do debug the slow memory leaks, and the bad ones don't debug the slow ones. Besides, any memory leak in a Java program is possible in a C app, so you are eliminating a class of leaks, not replacing them with harder to find leaks. Thus your entire argument is moot. Furthermore, where are you getting the idea that Java memory leaks are going to be slow while C memory leaks are going to be fast? I've seen slow C memory leaks and fast Java ones. I can think of nothing regarding the nature of garbage collection that would effect the speed of the leak.

      "I have a good analogy - Firefox. I use FF a lot, I like it, but it does tend to increase its memory usage over time, and has been rightly criticised for it. Now, I'm sure the 'bug' is an aspect of its design and not a programming bug (and I don't want to start a FF memory discussion - I'm only using it as a real-world example) but just imagine if *every* program was like FF - slowly using more and more RAM over time until you restarted it."

      First, thats not an analogy, thats an example. Second, Firefox is not an application, at least not in this day and age. Today its a platform for web applications which are just vulnerable to memory leaks as any other. If that cool new javascript app that is running on the page you are loading leaks memory, there really isn't a whole lot Firefox can do.

      Third, I fail to see your point. Do memory leaks suck? Of course. Is it best to get rid of them? Of course. Will garbage collection get rid of memory leaks? Of course not. Will they make the problem any worse? No, any code that leaks in Java will also leak in C. Will it make it better? Of course, there are types of leaks which simply are not possible in Java. Those will be eliminated resulting in fewer leaks (though it is of course impossible to eliminate the completely).

      --
      Mathematics is made of 50 percent formulas, 50 percent proofs, and 50 percent imagination.
    66. Re:Stupid Slashdot headline by cryptoluddite · · Score: 1

      The operating system does not run finalizers on parts of memory, because it can't, because all it knows about are pages. That's the malloc/free world.

      It also differs by the part you cut out with [...]. Imagine that.

      Comparing a memory leak with manual memory in C/C++ with a 'leak' in Java/C# is like saying *(char*)0 and ((Object)null)->method are both memory faults. In some sense, technically, the latter is generally the processor hitting page 0 and faulting. But in practice it is so different that it is not helpful to call it or think about it the same way.

    67. Re:Stupid Slashdot headline by nwbvt · · Score: 1

      Aside from the fact that, as mentioned, there is current development on real time garbage collection, when did I say GC languages were appropriate for every task?

      --
      Mathematics is made of 50 percent formulas, 50 percent proofs, and 50 percent imagination.
    68. Re:Stupid Slashdot headline by nwbvt · · Score: 1

      "Actually the good companies do debug the slow memory leaks, and the bad ones don't debug the slow ones."

      That should have read "Actually the good companies do debug the slow memory leaks, and the bad ones don't debug the fast ones."

      --
      Mathematics is made of 50 percent formulas, 50 percent proofs, and 50 percent imagination.
    69. Re:Stupid Slashdot headline by psmears · · Score: 1

      If the memory is unused (no longer referenced) it will be freed. Please read carefully—you asked me to give a definition of a memory leak, and I specified memory that is no longer needed. I didn't say no longer referenced. The problem is, code can keep a reference to memory even when it doesn't need it (which would, of course, be a bug). It's a memory leak, just like one from not freeing a malloc()-ed pointer in C. It just looks different in the code :-).
    70. Re:Stupid Slashdot headline by psmears · · Score: 1

      just use valgrind, and you can stomp out these problems quickly.

      That's true, but only on a good day :-). On a bad day your uninitialised pointer will happen to point to valid, allocated memory (Valgrind won't detect that) and you'll overwrite something you shouldn't. On another bad day, the second free() of a block, or an access to its contents, will happen after Valgrind has decided to give it to someone else (it only hangs on to freed blocks for a limited time). Or your program uses mutexes in shared memory, so Valgrind doesn't handle it well. Or on a really bad day, the problem will only exhibit itself on platforms other than x86, where Valgrind won't help at all :-(.

      Valgrind is a truly awesome tool, but it's not perfect by any means, and you can still end up spending lots of time debugging obscure problems (I know I have...).

    71. Re:Stupid Slashdot headline by psmears · · Score: 1

      What about these other issues?

      What about them? ;-)

      Seriously though, I was listing things that are problems with common languages using manual freeing, so I'll go through yours from a similar point of view:

      6. Yes, this is another good point, and (some) GC schemes solve this by moving objects around during GC—so another win for using GC.
      7. This is true, but it's more a difficulty in using GC in non-GC languages than a problem with manual freeing :).
      8. Arguably this is a win for C++ with RAII: the 'finalise' methods provided by GC languages are often not deterministic enough to be useful (for example, using 'finalise' to close a file means you don't know when the file will get closed, so it might not have been closed by the time you need to open it again...
      9. As with any discussion, real-time brings its own set of problems :-)

    72. Re:Stupid Slashdot headline by Heir+Of+The+Mess · · Score: 1

      Yep, they should have used my weak event handler factory http://www.codeproject.com/csharp/weakeventhandlerfactory.asp

      --
      Australian running a company that does C# / C++ / Java / SQL / Python / Mathematica
    73. Re:Stupid Slashdot headline by mrwolf007 · · Score: 1

      Ok, luckily "no longer needed" is about as precise a term as possible.
      What next, the compiler decides the program is unnecesary because someone else already wrote a similiar program?
      How is the compiler to know that memory is no longer needed?
      Add a "i got a better guess what the programmer intends than himself"-feature? Please, do get realistic.
      The main difference between a memory leak in C/C++ and what you describe is the following fact:
      There is now way to access the memory in C/C++ once the last pointer has been cleared, BUT as long as some object still holds a reference to this "unneeded" memory you can still access it (and how is the compiler or VM to know that you dont wish to do that later?).
      These are two fundamentaly different coding errors. The later beeing an error that can occur in C++ as well and no C++ coder would call it a memory leak (i wouldnt and i cant imagine a decent C++ coder would call it a memory leak).

    74. Re:Stupid Slashdot headline by gbjbaanb · · Score: 1

      Besides, any memory leak in a Java program is possible in a C app, so you are eliminating a class of leaks, not replacing them with harder to find leaks. Thus your entire argument is moot. You mean the article's memory leak - where they 'deleted' an object they'd stored and then were surprised to find that the object was still present in the app? If you tried that in C you'd segfault. So, yes, here is an example of a memory leak in Java that would not be present in C. Thus my entire argument is correct.

      My main point was though, that anywhere you have an advanced feature that is billed as letting you get away without thinking, you're going to have to think about it anyway; and less experienced programmers will get themselves into trouble when using it.
    75. Re:Stupid Slashdot headline by nwbvt · · Score: 1

      " You mean the article's memory leak - where they 'deleted' an object they'd stored and then were surprised to find that the object was still present in the app? If you tried that in C you'd segfault. So, yes, here is an example of a memory leak in Java that would not be present in C. Thus my entire argument is correct."

      I haven't developed in C#, but at least in Java you can't delete objects. All you can do is clean out references.

      They would have only gotten a segfault had they actually called the deconstructor in C. Which means they would have had to think about the scenario regarding passing obstacles a bit longer. And had they thought of that scenario in the first place, I'm guessing they would have remembered to clean out all references in their C# code.

      "My main point was though, that anywhere you have an advanced feature that is billed as letting you get away without thinking, you're going to have to think about it anyway; and less experienced programmers will get themselves into trouble when using it."

      Are you trying to imply that less experienced programmers don't screw up with languages like C? Because if so, you are way off. The only difference between an inexperienced programmer writing in C and one writing in Java is that the C programmer is going to have many more memory leaks because there will be a lot more for them to remember.

      And lets take your argument to the next logical conclusion. Libraries are billed as things that help people develop while thinking less, but you still have to think about them. You have to think before you use that ArrayList implementation of a collection if it really is the right data structure and not a HashSet. Many times I've seen people who just use ArrayLists (or even Vectors) in Java programs when what they really need is something like a HashSet. So does that mean we should do away with all libraries and force developers to write their own data structures to force them to think about what kind they really need? No, because the less experienced programmers are still going to make the same mistakes, only they will make more of them since they have to develop so much more stuff.

      --
      Mathematics is made of 50 percent formulas, 50 percent proofs, and 50 percent imagination.
    76. Re:Stupid Slashdot headline by luzr · · Score: 1

      I guess you misundrestood a bit the issue. I do not say that finally is there to release references, so that GC can collect. No. The finally is there because you need to release non-memory resources in case of exception. Sure, only C++ provides an alternative solution to the problem - destructors, OTOH C++ is accidentally the only currect alternative for C#/Java. And the concept of destructors is incompatible with GC (synchronous vs asynchronouse problem). That is the why C++ can do withou finally, while C#/Java cannot. (Summary: GC -> destructors not possible -> we need "finally" to release non-memory resources. Therefore: "Finally have everything to do with GC".).

    77. Re:Stupid Slashdot headline by minniger · · Score: 1

      Sorry, still think you're playing a little fast and loose with things.. First you say finally is there for non-memory resources... then at the end you say that finally has everything to do with GC. So yeah.... you've lost me since GC is about memory resources whereas finally is for other resources.

      Finally -> point at which you can do something to resources affected by the try/catch blocks. GC may or may not occur at some point in the future.

      Destructors -> Clean up memory and other resources used by a class. With the expectation that the class will be freed in an appropriate way when you are done with it.

      Kinda/sorta the same thing. Just in java you tend to not worry about the memory part so => less to do => less to screw up.

      There's no reason you couldn't have a destructor in a GC lang... java's finalize is a little bit like it for special circumstances.

      To bring the whole thing back around to TFA they didn't manage their resources (wasn't a memory leak as such)... which had nothing to do with a GC bug or a failure of GC to deliver on it's benefits. If they had done the project in C++ they would have likely had the exact same problem AND it would have most likely taken longer to build the system.

    78. Re:Stupid Slashdot headline by luzr · · Score: 1
      Well, ok. Look at what you have written: GC - manages memory. Destructor - manages resources. That is exactly the point. In Java/C#, you need finally, because there is no other way how to do it. The whole language structure and usage is based on using GC.

      And no, you cannot really have safe destructors in GC language. I mean, you can try, but the whole mess will likely be unmanagable and way error prone. And finalizers are not destructors by a long shot - they are asynchronous.

    79. Re:Stupid Slashdot headline by minniger · · Score: 1

      But you're comment says resources==memory. Destructors handle memory and non-memory resources. Finally is for non-memory resources. Finally may be a consequence of GC but finally doesn't imply GC.

      I'm not saying you don't need finally... I was just saying that the failure of the application was not GC related and that C++ didn't solve the problem for a lower cost. That is, people bag on GC languages oftentimes when they haven't really used them enough to appreciate the benefits. This seemed to be the case with the original poster.

      Yes... finalizers are not destructors which is why I qualified the statement. In certain situations you MIGHT use finalize to do something similar to a destructor.

    80. Re:Stupid Slashdot headline by luzr · · Score: 1
      Nope. What I say is that memory is resource manageable by destructor. That is not the same thing. Whereas non-memory resource are NOT manageable by GC. Therefore, GC based language needs "finally". Finally does not imply GC, but GC with exception handling implies "finally".

      BTW, I am not even advocating C++ over GC languages. I am not commenting about the fault in the application. I am only responding to your comment that "finally" has nothing to do with GC. It has. Almost everything ;)

    81. Re:Stupid Slashdot headline by minniger · · Score: 1

      Ok... I see where we're missing each other. We can agree that GC is about memory management (http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) )... Finally is about non-memory resources and destructors are used to deal with both.

      And you are saying that a GC lang must have a finally block (must it really?) therefore finally has everything to do with GC.

      I'm approaching it from an end user programmer point of view. My finally block has little to nothing to do with the GC other than the scope. I (as a programmer) use the finally block to deal with non-memory resources. Therefore based on the original parent's comments they dig at GC was looking rather uninformed.

      So i take your point.. I just wouldn't put things quite that way.

    82. Re:Stupid Slashdot headline by luzr · · Score: 1
      My finally block has little to nothing to do with the GC other than the scope. I (as a programmer) use the finally block to deal with non-memory resources.

      Well, maybe you could try a language where resource management is really automatic for a change (C++) :) So i take your point.. I just wouldn't put things quite that way. Fair enough. Thanks for interesting chat.

    83. Re:Stupid Slashdot headline by Anonymous Coward · · Score: 0

      hows about programmers work with the _simple_procedural_machine_ they are operating Uhhh... they're only pretending to be working on a _simple_procedural_machine_ because ...

      What?

      instead of pretending it's some kind of whiz bang math abstraction... Since that's exactly what a PROCESSOR is (so it can look like a _simple_procedural_machine_), are you suggesting we code at a lower level? Oops, we can't be 'coding', because interpreting codes is whiz bang math abstraction.

      Let's just write our programs on paper and fold them into little airplanes so you don't have to worry about whiz bang math abstraction.
    84. Re:Stupid Slashdot headline by caywen · · Score: 1
      I gotta nitpick a few things I think are small but important in your comments:

      Sure, C++ programmers consider it rocket science and discuss ad nauseum their clever smart pointer techniques and [clip] ... That's because they're now used to getting through life with no arms and artificial legs.
      I think you're being unnecessarily derogative of C++. Different tools for different jobs. There are many scenarios where deterministic, manual GC has benefits over automatic GC. I wouldn't characterize having deterministic destructors in place of GC as having no arms and no legs.

      Look, here's a thought experiment: if I modified C++ so that the end of life of every int and char had to be declared. Would that be reasonable? Would that be acceptable? I think not. So how can it be argued that this is reasonable or acceptable to require in a programme that simply happens not to have ints and chars as its domain of computation?
      C++ is pretty consistent here. You can new up an int and char and require them to be deleted, just like I can instantiate classes/structs on the stack. Nothing in C++ says I ever have to call new/delete. And, even in java or .net, you often have to essentially manually manage freeing certain kinds of resources anyways (eg. database connections).

      Garbage collection, like almost all other high level language features, is hard to get right in a hard real time environment, and (more or less) requires that the language by type safe.
      Maybe I'm splitting hairs, but garbage collection is as much a part of the runtime environment as the language. The language expresses the ability to take advantage of garbage collection, but the feature doesn't really come from the language. At least, not with Java nor C#.
    85. Re:Stupid Slashdot headline by porpnorber · · Score: 1

      I think you're being unnecessarily derogative of C++. Different tools for different jobs.

      I freely admit I never know what to do in this situation. The rhetoric texts will say that the response I am about to make is a fallacy; the experience is much like that of trying to argue against naive creationism—I just don't know what to say. But look, I'm quite serious and not at all trying to be inflammatory; if you believe that C++ is not a complete disaster, then it makes me suspect that programming language design was not part of your curriculum at school. It's just a stupendously horrible job. I would not give it a passing grade. I guess I could pull out my copy of Stroustrup and go through it line by line, but there just isn't the space here. I'm genuinely sorry if that sounds ranty, but words truly fail me. Each application may have a tool, but it does not follow that each tool has an application.

      There are many scenarios where deterministic, manual GC has benefits over automatic GC. I wouldn't characterize having deterministic destructors in place of GC as having no arms and no legs.

      And I'm sorry if it read like that. I meant to suggest that having no garbage collector is like having no legs; the missing arms are, if you like, some of the language's many other design features. ;)

      I do agree that there are some circumstances for which we do not yet have good enough implementations of garbage collection; generally, however, I would suggest a C++ programmer use C or even assembly code for programming at this level, though these are merely the most familiar options.

      C++ is pretty consistent here. You can new up an int and char and require them to be deleted, just like I can instantiate classes/structs on the stack. Nothing in C++ says I ever have to call new/delete.

      Well—except that if you 'new' an int, you don't get an int, you get a pointer to int. It's a different thing. And if you don't new your structs then you can't make dynamic or even variable sized structures; you can't safely pass pointers; you can't build linked structures; you have no way of simulating function objects; and you can only really make use of methods in the context of callback structures—you're basically hosed as regards basic programming techniques. See, the thing is that C++ programming relies heavily on abstraction, but the abstraction mechanisms it provides operate specifically through pointers (this all harkens back to the long and strange tradition whereby C programs pass structures by reference, even though struct declarations describe layout at the referent. In the context of the language family, the ability to pass structs around as values is the innovation, not the pointers. This may be ancient history now, but it wasn't when C++ was originally devised...). Without a garbage collector, pointers to heap objects are dangerous; but pointers to stack objects are suicidal and semantically anaemic.

      And, even in java or .net, you often have to essentially manually manage freeing certain kinds of resources anyways (eg. database connections).

      Ouch! Where did you get the idea that I was advocating Java or .Net? Garbage collection may be necessary to a modern high level language, but it is far from sufficient. Though you have a point: when managing resources external to the language system some accomodation generally must be made. Though it's subtle: one of the ways in which Un*x scores over other operating systems designs is that unlinking a file does not cause it to be deleted; there is a garbage collector, and so long as there is an fd (an O/S level pointer, if you like) open on something, it is retained. That's a good and useful idiom; but not all system designers believe in garbage collection, you see. So, yes, systems do have edges; it's an issue.

    86. Re:Stupid Slashdot headline by caywen · · Score: 1

      if you believe that C++ is not a complete disaster, then it makes me suspect that programming language design was not part of your curriculum at school.
      Well, that'd be a wrong suspicion, then. It's probably much more appropriate and reasonable to believe that C++ is possibly overcomplicated, but brings some very useful facilities to the table. I'm pretty sure they wrote most manage code environments using it, so characterizing it as a "complete disaster" is just hyperbole.

      Well--except that if you 'new' an int, you don't get an int, you get a pointer to int.
      When I 'new' a MyClass, I get a pointer to a MyClass. There's no except.

      however, I would suggest a C++ programmer use C or even assembly code for programming at this level, though these are merely the most familiar options.
      Writing a multithreaded garbage-collecting runtime environment entirely in C and/or assembly? You must be joking.

      Without a garbage collector, pointers to heap objects are dangerous; but pointers to stack objects are suicidal and semantically anaemic.
      Pointers to anything is dangerous - so are scissors and cars. And saying pointers to stack objects is "suicidal" sounds like more hyperbole. Based on your comments - and I really hate to make this kind of accusation and I hope you don't take it personally - I think you have very limited experience with C++ given many things you've written that don't ring true. That said, GC is a great facility.
    87. Re:Stupid Slashdot headline by porpnorber · · Score: 1

      Well, I certainly can't make head or tail of this conversation.

      Well, that'd be a wrong suspicion, then. It's probably much more appropriate and reasonable to believe that C++ is possibly overcomplicated, but brings some very useful facilities to the table.

      If by 'possibly' you mean an order of magnitude, perhaps. And certainly C++ attempts to deploy some useful ideas, but it hardly does it in a useful or manageable way. Seriously, can you name anything that C++ does right? To take a random example, the templates look interesting, until you realise that they don't give you code sharing, that they are not required to generate code transparently into libraries, and that the rules for the binding of names inside them are beyond human intuition. Or an older one: privacy control looks interesting, until you realise that it's been implemented in such a way as to require most code to be lifted from the implementation fie to the interface file, providing negative information hiding.

      When I 'new' a MyClass, I get a pointer to a MyClass. There's no except.

      Yes yes yes. What I mean to say is, than when you are packaging up data for the users of a module, you need to use pointers for class data in order to get the OO-ish semantics. But the facilities for numeric data rely on them being unboxed. This means, among other things, that it's unnecessarily hard to provide opacity for simple values. It's a bizarre state of affairs in C++; how it got carried across into Java I will never understand (and recently they've tried to patch around it, and that's a mess too...).

      Writing a multithreaded garbage-collecting runtime environment entirely in C and/or assembly? You must be joking.

      You boggle me. Why on earth not? We write operating systems in C. In olden times, we wrote them in assembly. I certainly wrote my garbage collectors, multithread executives, core library routines and whatall in assembler when I was doing such things. It wasn't especially hard, and it certainly wasn't technically inappropriate. Did something happen along the way to make it impossible?

      In any event, C++ is certainly not the language for such tasks, because they share the common property that tight control of data representation is an absolute requirement. Since C++ does not provide this once you step outside the almost-C-compatible subset, why not save yourself pain and use C? (I mean, not that C is fantastic about it. What one wants is a language whose representation control is good enough that sending a data structure straight out on the wire is a plausble programming strategy.)

      Pointers to anything is dangerous - so are scissors and cars. And saying pointers to stack objects is "suicidal" sounds like more hyperbole.

      Matter of fact you'll definitely hear me advocating the banning of private cars, at least in urban areas. I simply do not understand how people can argue about whether money is being spent on antiterrorism measures that could be spent on education (for example) while random people are allowed to drive those things. Does nobody pay any attention to the statistics?

      But (in the absence of an appropriate static checking mechanism, of course) I'll stand by my characterisation of pointers to stack objects as suicidalhopefully it's the process that dies and not the user, of course, but (in the case of closures) it was famously one of the great design flaws of Algol 68—or does my memory fail me?

      Based on your comments - and I really hate to make this kind of accusation and I hope you don't take it personally - I think you have very limited experience with C++ given many things you've written that don't ring true.

      Well, only five or six years of solid nine-to-five experience with C++, which I guess does not compare well to my C experience, if you want to

  6. C# Garbage... by dgun · · Score: 1

    collection

    because the objects were still registered as subscribers to an event, they were never getting deleted.

    I wonder if the Java garbage collector does this also?

    --
    FAQs are evil.
    1. Re:C# Garbage... by elFarto+the+2nd · · Score: 1

      More than likely. Basically they're saying "C# didn't garbage collect objects that were still in use!", which is quite obvious. I've been caught out a couple of times by not thinking through which object have references to other objects, and end up leaking memory. Other times I've come across bugs in the JDK where a class refuses to let go of an object, causing a leak (In fact, it was something todo with the focus manager IIRC, keeping a reference to a GUI component that I had disposed of).

      Regards
      elFarto
    2. Re:C# Garbage... by JanusFury · · Score: 2, Informative

      It would have to, because otherwise you could register an anonymous class or other similarly constructed object as an event handler, release all your other references, and the GC would collect it while it still needs to be able to recieve messages. (That, or the GC would unregister the event handler, which would be utterly mysterious to debug if you didn't already know the intricacies of the GC, especially since you have no way of predicting when your event handler is collected).

      This problem is actually less drastic in C#, since you have the ability to instantiate anonymous methods (delegates) instead of anonymous classes when doing event handling, and they have lower overhead. So even if you mess up your resource management, it's still much easier to control your resource usage because you have access to cheaper primitives to work with.

      --
      using namespace slashdot;
      troll::post();
    3. Re:C# Garbage... by dgun · · Score: 1

      because otherwise you could register an anonymous class or other similarly constructed object as an event handler, release all your other references

      Oh. * scratches head *

      But in this case, they were asking the GC to destroy the object. So why could that not be a special case?

      Computerz are hard.

      --
      FAQs are evil.
    4. Re:C# Garbage... by cnettel · · Score: 1

      They did no such thing, because there is no such thing in C#. They might have implemented IDisposable and called Dispose, but then they had done it incorrectly if the event handlers still worked...

    5. Re:C# Garbage... by Weedlekin · · Score: 4, Informative

      As is the case with Microsoft's GC, Java's won't delete things that are still being referenced by other things, because it quite reasonably assumes that an object which is referenced by another object that hasn't itself been marked for collection isn't garbage.

      The main problem with garbage collectors (I like GCs, so this isn't a diatribe against them) is that far too many mediocre programmers assume they have a magical ability to know precisely what they want their code to do. The reality of course is that they use algorithms to decide what should be collected, when it should be collected, and how it should be collected, and those who are unfamiliar with the particular strategies that their GC uses can therefore not only write code with more than a few memory leaks, but also code that results in the GC being used so inefficiently that it does vastly more work than would be necessary if the same functionality was implemented in a slightly different way.

      There are plenty of articles about Java memory leaks that can be found by Googling "java memory leaks". Googling "java GC tuning" will produce some useful links to articles containing tips on ensuring that it's not used inefficiently.

      --
      I'm not going to change your sheets again, Mr. Hastings.
    6. Re:C# Garbage... by Anonymous Coward · · Score: 0

      In Java you can use WeakReference which were created for use in things like listener and subscriber patterns.

      The C# dispose method is for cleaning up unmanaged resources. Memory is a managed resource and the GC takes care of that. Using dispose also presupposes that you know what you are doing since using such an object after it has been disposed is going to cause bad things to happen when you try to use those disposed resources, much like using a deallocated object in an unmanaged language will cause bad things to happen.

      This just proves the saying that if you try to make something idiot proof, the world will create a better idiot.

  7. no one claims C# prevents wasting memory... by saurik · · Score: 3, Informative

    Just because a language is garbage collected doesn't mean you can't "leak" memory (in the more standard definition of "waste memory over time"), it only means you can't completely lose track of references to objects (which is often used as a more technical definition of "leak"). It is quite common for people coding in such languages to accidentally generate live object structures that are mostly made up of garbage that they should have released their references to. Put another way: these people's program was legitimately claiming memory and never releasing it due to their limited understanding of how event handlers work.

    1. Re:no one claims C# prevents wasting memory... by someone1234 · · Score: 1

      Well, it seems like these event handlers need to be reworked so people who "don't care with pointers" can use them effectively.
      I personally prefer using C++ with Valgrind not some fancy language with garbage collection.

      --
      Patents Drive Free Software as Hurricanes Drive Construction Industry
    2. Re:no one claims C# prevents wasting memory... by Anonymous Coward · · Score: 0

      A memory leak is impossible in Java, since a memory leak means the program can't access the memory anymore (in C++ you wouldn't be able to delete that reference, because you lost it). In Java, what you have is that you accumulate objects in an array, a map or a collection. So you end up with too many objects in memory (which I call object polution), but using a debugger you can find them. That's is not the case with real memory leaks.

      Although object pollution can be better detected and diagnosed using profilers rather than debuggers. If you don't have profilers here is a simple trick you can use:

      1. Disable all caches. (Isn't this obvious?)
      2. Create all objects using factories.
      3. Use interception (JDK dynamic proxies for example) to detect each allocation and to have a map of all allocations (so that you know how many objects are created). You may gather how big objects are.
      4. Determine under which operations the amount of memory should be the same. For example "between logins and logouts, the amount of memory should remain the same".
      5. Now run the program and detect if number 4 performs as expected or not. If ok, you are done.
      6. Use something like Spring to intercept object relations. Print those using the sizes you gathered in 3. Sum them up. Do this before login and after logout.
      7. Compare both printouts. They should be identical.

  8. This is not a C# memory leak! by Tim+C · · Score: 5, Informative

    This is a programming error, plain and simple. From TFA:

    Though we thought we had cleared all references to old entries in the list, because the objects were still registered as subscribers to an event, they were never getting deleted.

    So references were held to the objects in two places - the list of encountered obstacles, and the list of event subscribers. They were being removed from the list of encountered obstacles, but not being unsubscribed from the event.

    How do you think event subscription works? Something has to hold a reference to the objects that are subscribed to the event! That thing is going to hold a reference until you unsubscribe the object - it neither knows nor cares about any other list of references you may be maintaining separately, how could it?

    This is a coding error. A subtle, non-obvious one perhaps, but a bug nevertheless. It is not an error in the CLR, and in fact the article never paints it as such. That particular bit of spin is wholly down to the submitter.

    1. Re:This is not a C# memory leak! by sohp · · Score: 1

      This is a coding error. A subtle, non-obvious one perhaps, but a bug nevertheless. Not *that* subtle, for those of us who know what we are doing. Yet let's look at the article:

      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. It couldn't be the list of obstacles: right there was the line where the old obstacles got deleted. Sitting in a McDonald's the night before the competition, we still didn't know why the computer kept dying a slow death. Because we didn't know why this problem kept appearing at 40 minutes, we decided to set a timer. After 40 minutes, we would stop the car and reboot the computer to restore the performance. I read that and I say "scrubs". Rebooting is a NASTY HACK. Pardon me for a little bitterness but I've seen this over and over in embedded systems by hardware types trying to be programmers, even from such prestigious places as Princeton. Some brilliant hardware guys will devalue the software driving (bad pun haha) the thing that it gets slapped on as a low-priority task to be done "after the hardware works". It's not helped by the occasions when, for example, a signal processing whiz is too impatient to work with a programmer without the same background to spec out software for cylindrical patch antenna tools.
    2. Re:This is not a C# memory leak! by GWBasic · · Score: 1

      So references were held to the objects in two places - the list of encountered obstacles, and the list of event subscribers. They were being removed from the list of encountered obstacles, but not being unsubscribed from the event. How do you think event subscription works? Something has to hold a reference to the objects that are subscribed to the event! That thing is going to hold a reference until you unsubscribe the object - it neither knows nor cares about any other list of references you may be maintaining separately, how could it? This is a coding error. A subtle, non-obvious one perhaps, but a bug nevertheless. It is not an error in the CLR, and in fact the article never paints it as such. That particular bit of spin is wholly down to the submitter.

      This kind of error is common with inexperienced C# programmers. I haven't come across any documentation that talks about the need to unregister events.

      The first version of .Net had a calendar control that didn't unregister an event handler after it was disposed. If you registered an event on the calendar control, your form would never be collected, unless you used reflection to work around the issue.

      At my job, I had to fix a bug where a C# programmer forgot to unregister events in his Dispose method. Fortunately, in our case, the bug manifested itself during simple use cases. As soon as I reminded him that Disposing an object isn't the same as getting it collected, he realized that he needed to unregister his events.

      I'm not surprised that this happened in an academic project; it's a good learning mistake.

    3. Re:This is not a C# memory leak! by Lao-Tzu · · Score: 1

      Yes, this is clearly not a "memory leak". It is a software bug.

      From the tone of this article, it seems clear that the developers knew that memory usage was growing and objects were not being reclaimed as they should have been. Given the GC environment they were working in, they should have just sat down and thought: what could cause that? Assuming that the runtime is working properly (a pretty good assumption, given its widespread use), there is only one possibility: objects aren't being reclaimed because they are still being referenced.

      A quick Google search would have come up with a list of reasons why this can happen, including the objects being subscribed to an event handler. It is a common cause of memory leaks in managed environments (eg. Java & .NET). This team should have spend some time thinking about the problem, rather than trying to fix it with a terrible hack like rebooting the machine at given intervals.

  9. 3 seconds with valgrind by nyet · · Score: 0, Flamebait

    AND there's no need for this "trial" version bullshit.

    What a bunch of noobs.

  10. Shasdotvertisiment at is best by mariuszbi · · Score: 3, Insightful

    I've RTFA, is wasn't a memory leak caused by C#, is was caused by bad programming. After that,the whole article starts to advertise some obscure profiling tool. Maybe they should should have written the whole thing in C++ and use valgrind instead. Just an ideea...

    1. Re:Shasdotvertisiment at is best by Jartan · · Score: 1

      Was there somewhere that something claimed it was a leak caused by C#? I think this was more of a "Oh look garbage collection doesn't save you from crappy memory mangement after all". Something all of us who have a clue already knew.

      Pretty useless point to make though. People aren't using C# for memory management. They are using it because Microsoft basically no longer does any worthwhile C/C++ gui development.

    2. Re:Shasdotvertisiment at is best by Bill+Dog · · Score: 3, Insightful

      ...the whole thing in C++ and use valgrind instead.

      Or better yet, in C++ and use the RAII idiom. I.e. utilize the power of deterministic destruction, that C# and Java lack, to arrange it so that resources, including but not limited to just memory, are auto-freed. (You *can* run into this same kind of problem using reference-counted smart pointers in C++, but happily much of the time they aren't needed.)

      --
      Attention zealots and haters: 00100 00100
    3. Re:Shasdotvertisiment at is best by HangingChad · · Score: 2, Informative

      I've RTFA, is wasn't a memory leak caused by C#, is was caused by bad programming

      We've had similar trouble trying to build big systems on an MS platform. Stubborn memory leaks that don't seem to have a common cause. It's happened in VB and C#. You can't blame them all on bad programming because we've had similar problems from completely different groups of programmers with varying skill levels. We build mainly web apps and this was a desktop app but their description was strangely familiar.

      It's pretty callous to blame the programmer when they trust garbage collection to do its job. That was one of the big selling points of the whole .NET framework from day one. This great tool that manages memory for you. Like a lot of what MS sells it turned out to me more of a false sense of security.

      --
      That's our life, the big wheel of shit. - The Fat Man, Blue Tango Salvage
    4. Re:Shasdotvertisiment at is best by Anonymous Coward · · Score: 0

      Headline: C# Memory Leak Torpedoed Princeton's DARPA Chances

    5. Re:Shasdotvertisiment at is best by MikkoApo · · Score: 1

      utilize the power of deterministic destruction, that C# and Java lack, to arrange it so that resources, including but not limited to just memory, are auto-freed. That is incorrect. Java has had WeakReference since 1.2 release which was in 1998.

      Weak reference objects, which do not prevent their referents from being made finalizable, finalized, and then reclaimed. The catch is that all code registering disposable objects like events and listeners should use references or objects which use refences, like the WeakHashMap. Sometimes getting that kind automation to work _right_ requires a bit of thought though but abstracting the functionality behind a suitable interface makes things easier to figure out. A generic Eventbroker which uses a Map to hold eventlisteners would enable easy switching between gc'ed (WeakHashMap) and non-gc'ed (any other Map) functionality.
    6. Re:Shasdotvertisiment at is best by Anonymous Coward · · Score: 0

      I'm not that familiar with RAII, but isn't that for 'allocate at procedure start and deallocate at procedure end' drudgework, and useless for things like keeping a variable set of allocated objects which are also referenced elsewhere?
      I don't see how it would apply for the problem described in the 'article', care to go more in detail?

    7. Re:Shasdotvertisiment at is best by DerWulf · · Score: 1

      You CANT garbage collect a live object in a managed language. You SHOULDN'T free memory that will still be read in an unmanaged language. The former will run until the memory runs out while the later will do god knows what.

      --

      ___
      No power in the 'verse can stop me
    8. Re:Shasdotvertisiment at is best by Anonymous Coward · · Score: 0

      It's pretty callous to blame the programmer when they trust garbage collection to do its job. That was one of the big selling points of the whole .NET framework from day one.


      Everyone gets the tools that he deserves.
    9. Re:Shasdotvertisiment at is best by kailoran · · Score: 1

      That is incorrect. Java has had WeakReference since 1.2 release which was in 1998.
      You are wrong. Weak references != deterministic destruction.
    10. Re:Shasdotvertisiment at is best by __aasmho4525 · · Score: 1

      that said, in almost all normal cases, had the event registrations been done with weak references, this problem would have been a non-issue.

      the gc would have had lots and lots of opportunities to run before consuming the entire heap...

      cheers.

      Peter

    11. Re:Shasdotvertisiment at is best by kailoran · · Score: 1

      yeah, but anyway, in this specific case, how do you guarantee that the gc run doesn't lock up the entire system for half a second (during which the car rams into a wall)?

    12. Re:Shasdotvertisiment at is best by Anonymous Coward · · Score: 0

      Real programmers release their own resources. GC is for whimps.

    13. Re:Shasdotvertisiment at is best by smellotron · · Score: 1

      utilize the power of deterministic destruction, that C# and Java lack, to arrange it so that resources, including but not limited to just memory, are auto-freed.
      That is incorrect. Java has had WeakReference since 1.2 release which was in 1998.
      Weak References have nothing to do with RAII. RAII is more along the lines of "replace all of the code in finally clauses with encapsulated cleanup by the objects themselves". By converting dynamic (and thus scopeless) resource allocation into stack-based scoped allocation, your cleanup is guaranteed to run when you decide. Java finalizers are similar, but are nondeterministic and may never execute if the JVM decides it so, making them useless for cleanup tasks.
  11. Re:As a C kernel programmer... by JanusFury · · Score: 2, Insightful

    It's not as if C doesn't leak memory when you mishandle resources. All these people needed to do was spend 5 minutes with the (free) MS .NET profiler and look at the allocation and GC graphs, and they'd be done.

    --
    using namespace slashdot;
    troll::post();
  12. Serves them right... by Anonymous Coward · · Score: 0, Flamebait

    For attempting to use Windows to drive a car. What? are they fucking crazy?

  13. Categorization of Resource Management Issues by mr_mischief · · Score: 3, Funny

    This section totals 15 points.

    Background:

    There are more types of resource leaks than just memory leaks. A memory leak is when your program keeps hold of memory it's not using. An object leak is when your program keeps hold of objects it's not using. A file descriptor leak is when your program fails to reuse the descriptors for files it has closed and will not reopen. Many other types of leaks could be considered.

    Exercises:

      1. Determine which issue this scenario describes.
      2. Figure out which issue can be handled by automatic memory management.
      3. Discuss whether, and if so why, the answers to Exercises 1 and 2 mean there is some conceptual discord between the wording of the scenario and the use of the term "memory leak".

  14. stop programming hardware, please! by QuantumG · · Score: 1

    Wow. This is just totally incompetent. I know you're students and all and have no real world experience, but this is just frightening. Stay away from the hardware please, you'll get someone killed one day.

    --
    How we know is more important than what we know.
    1. Re:stop programming hardware, please! by Anonymous Coward · · Score: 0

      And you should just stay away from people.

    2. Re:stop programming hardware, please! by Anonymous Coward · · Score: 0

      Really helpful remarks.

      You, pal, are an idiot...

  15. Re:As a C kernel programmer... by Anonymous Coward · · Score: 0

    So you think you're better than a garbage collector at preventing memory leaks? Well, maybe you are, but the chance that that is the case (and the chance that that would actually matter) is exceedingly close to 0%. Why stop at memory management? Why not write everything in assembly? Or machine language? People who avoid using useful tools merely because those tools aren't 100% perfect are almost always arrogant idiots who will get left behind as progress marches on.

  16. After by EEPROMS · · Score: 0, Troll

    hundreds of man hours and a few hundred thousand dollars we have finally put our finger on the problem "It was written in Microsoft's C#"...

  17. c#? by nekozid · · Score: 3, Interesting

    I don't see why they just didn't write it in C.
    They were using massive cooling systems and having very thorough code reviews, sounds like a perfect reason to use C over C#.

    1. Re:c#? by Anonymous Coward · · Score: 0

      If they made an error this stupid when writing C#, how do you expect them to even begin writing C code?

    2. Re:c#? by Antique+Geekmeister · · Score: 1

      By not wasting their time with 3 times as many lines of C# code? By having a much faster compilation time so tests can be done more quickly? By having free high quality profiling and debugging tools? By being forced to think about what their functions actually pass to each other, instead of waving their hands and saying "then a miracle occurs"? By having such basic errors fail more quickly, rather than after testing and in the field?

      Take your pick. I've done some comparisons for simple programs written in C and in C#, though I'm hardly expert in C#, and seen each of these apply at least once.

    3. Re:c#? by Ash-Fox · · Score: 2, Insightful

      By not wasting their time with 3 times as many lines of C# code?
      Heh... I've written C# programs that took a lot less lines than the equivalent program in C and vice versa.

      By having a much faster compilation time so tests can be done more quickly?
      Since when is compilation a issue with Microsoft Visual Studio .net? You can literally rewrite the code as the program is running.

      By having free high quality profiling and debugging tools?
      Other than the fact that they didn't know how to use the debuggers that come with Visual Studio .net, I really don't think they would of done any better with the same debuggers writing in C under Visual Studio .net.

      By being forced to think about what their functions actually pass to each other, instead of waving their hands and saying "then a miracle occurs"?
      There are tonnes of libraries in C that do automatically garbage collection, who says they wouldn't of done that in C?

      By having such basic errors fail more quickly, rather than after testing and in the field?
      Seeing how the data is accumulated by how many obstacles avoids at a specific speed. I don't see how using C would make it faster.

      Take your pick. I've done some comparisons for simple programs written in C and in C#, though I'm hardly expert in C#, and seen each of these apply at least once.
      I'm not impressed.
      --
      Change is certain; progress is not obligatory.
    4. Re:c#? by Antique+Geekmeister · · Score: 1

      That's funny. In the time I've seen Visual Studio taking to simply start up, especially in a complex environment, the machine might have already been banging into the walls.

      More seriously, you've revealed a serious issue, to wit: "Other than the fact that they didn't know how to use the debuggers that come with Visual Studio .net, I really don't think they would of done any better with the same debuggers writing in C under Visual Studio .net."

      I agree with you. Actually running the system for a trial run would have revealed the issue. You cannot rely on the cleverest debuggers in the world to replace an actual "smoke test", which clearly didn't happen.

  18. Why MS Windows? by belmolis · · Score: 1

    The immediate problem here was evidently a programming error, not a bug in C#, but I do wonder why they are using C# for this. That forces everybody involved to use MS Windows and eliminates the possibility of hacking the system if they need to as well as the source as documentation. If they want a C-level language with garbage collection, why not Java or D or any of several others?

    1. Re:Why MS Windows? by tmarklund · · Score: 2

      That forces everybody involved to use MS Windows
      Yeah, because everyone knows you cannot use C# under Linux.
    2. Re:Why MS Windows? by GrievousMistake · · Score: 1

      Sounds like a software developer's decision, picking the language/environment you're familiar with rather than the one appropriate for the job. You wouldn't normally make a control system that depended on a specific OS that was expensive and unsuitable for embedding.
      "If only we'd studied cybernetics..." is more like it. At least, I don't think they teach cybernetics with C# anywhere, but who knows what kind of crazy things they get up to at Princeton.

      --
      In a fair world, refrigerators would make electricity.
    3. Re:Why MS Windows? by belmolis · · Score: 1

      Well, you can sort of use C# on Linux. The Mono project is in various respects incomplete. According to the roadmap, their C# compiler is not up to date with Microsoft's. This may or may not affect what the Princeton team was doing, but still, why use an immature and only sort-of-portable language like C#? I can see it if there is some strong advantage to it, but so far I've seen no indication that there is one. So, what's the virtue of using C# over, say, Java?

  19. only 10KLOC? by basiles · · Score: 4, Interesting

    What surprises me most is the small size of their software, only 10 thousands lines of source code (I think that the average car processor already have these for today's cars -ignition & braking systems-). Given a team of a dozen programmers working for a year, I was expecting at least 50KLOC, or maybe 200KLOC (for example, the GCC compiler is 3MLOC, and the linux kernel has comparable size.)

    Of course memory leaks can happen with garbage collected languages, but these leaks are a little easier to find....

    Maybe they should have coded in a higher level language like Ocaml, Haskell.

    And yes, I'm sure most of an autonomous vehicle software is not low-level drivers, but in the planification & perception tasks. On such tasks, higher-level languages definitely make sense.

    I also did not understood what kind of libraries these teams are using.

    I'm also surprised that it is apparently so easy to get funded to have only 10KLOC inside a car!

    1. Re:only 10KLOC? by Anonymous Coward · · Score: 0

      What surprises me most is the small size of their software, only 10 thousands lines of source code (I think that the average car processor already have these for today's cars -ignition & braking systems-). Given a team of a dozen programmers working for a year, I was expecting at least 50KLOC, or maybe 200KLOC

      And there you have it, ladies and gentlemen, the type of attitude that is behind the vastness known today as Windows Vista.

    2. Re:only 10KLOC? by dkf · · Score: 3, Insightful

      What surprises me most is the small size of their software, only 10 thousands lines of source code (I think that the average car processor already have these for today's cars -ignition & braking systems-). Given a team of a dozen programmers working for a year, I was expecting at least 50KLOC, or maybe 200KLOC (for example, the GCC compiler is 3MLOC, and the linux kernel has comparable size.) Ah, but that 10kLOC needs to be the right 10k, and not all lines of code are the same (incrementing a variable is quite a bit simpler than calling a complex method). Plus you also don't know how many lines of code they threw away.
      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    3. Re:only 10KLOC? by belloc1 · · Score: 0

      Mod parent up!!! Ha

    4. Re:only 10KLOC? by comp.sci · · Score: 4, Insightful

      It's amusing to see that there are still people who believe in the old "more lines of code means better performance".
      Seriously, the performance of these cars is amazing, a huge step from just a few years ago. The hard part of this project was certainly not the programming, but the concepts behind the obstacle detection and such. This is not an implementation exercise, but more of an academic experiment to test out new ideas.

      (Nice work on mentioning Haskell to guarantee an upmod btw.)

    5. Re:only 10KLOC? by basiles · · Score: 1

      I was not assuming that more code means better performance.

      However, I am still surprised that a team of a dozen produced in one year a poorly written 10KLOC. It is poorly written because it did not achieve their goal: to win the race.

      I'm guessing is that even in these student teams, it is as everywhere else: One or two passionate developers, and all the others waiting & criticizing.

      And yes, I do know Brook's law (it doesn't take one month to 9 women to make a child).

  20. Hard/weak references for event handlers by djinnn · · Score: 4, Interesting

    I see quite a few comments from C/C++ coders who wonder whether managed memory people know how event handling works. If they knew a little more about managed memory languages, they'd know a reference does not have to be "hard": you can have a reference to an object that does *not* prevent garbage collection.

    So I guess the real question here is whether event handlers should be hard-referenced (as they are here), or just soft/weak referenced...
    From a developer perspective it's quite natural to think that, as long as his code doesn't hold any reference to an object, it should be garbage collectable. If registerEvent() shall hard-reference handlers, documentation should be *very* explicit about it (and the need to unregister a handler for GC to work on it).
    On the other hand, if handlers are not hard-referenced you can no longer register anonymous class event handlers...

    1. Re:Hard/weak references for event handlers by tgd · · Score: 5, Interesting

      Weak references also incur the overhead of a check on every call to ensure the object hasn't been cleaned up. This was sloppy, poorly tested code. The engineers on it made a mistake and caught it too late. It happens.

      The poster of the article was trolling, and not only trolled with the post, managed to get a troll posted to a slashvertisement which was not even trolling.

      Impressive on the part of the person who submitted it, but disappointing considering Taco's comments a few weeks back about articles that are truly nothing but advertisements.

    2. Re:Hard/weak references for event handlers by tietokone-olmi · · Score: 1

      Oh deary me. A check on every call? That's what, a compare and a "not taken by default" conditional jump? Plus registration of WeakPtr objects with the GC, but that's really just the creation cost.

      What's that one point zero two cycle cost these days... one ninth of a L1 cache hit's latency? Assuming an Athlon XP or 64 with a three instruction wide pipeline.

      Also. What the heck are managed language programmers thinking about micro-performance anyhow?

    3. Re:Hard/weak references for event handlers by Kaetemi · · Score: 1

      Balancing out the extra cost of the managed system, by writing efficient code. ;)
      It's much better than just writing slightly slower code.

      --
      Kaetemi
    4. Re:Hard/weak references for event handlers by tgd · · Score: 1

      The point is the people designing those languages do have to think about that level of performance.

      Damn near everything in .NET is wired up with events, that would start turning into a significant overhead.

      A better question is what the heck are managed language programmers not thinking about object references for?

    5. Re:Hard/weak references for event handlers by tietokone-olmi · · Score: 1

      But as I reasoned in the grandparent post, you can't balance out performance with micro-optimizations as most of them (like that one) are utterly and completely dominated by cache and (more importantly) memory latency. It's like saying that virtual methods are slow: perhaps if you call them in an inner loop but otherwise just bloody ignore them already.

      Using myself as a reference point, I'd say that people who think about things like that are just wanking to avoid actual work. And that's cool -- there's only so many hard coding hours one can put in after all. But sometimes this turns into "improved" code that's difficult to read and nigh impossible to modify while preserving the "improved"-ness.

    6. Re:Hard/weak references for event handlers by tietokone-olmi · · Score: 1

      Indeed. I'd guess that they're taught how to grind out Java with minimal skill rather than how to reason about object visibility and lifecycle. The market, apparently, needs shitty programmers too. What really sends me for a loop is that sometimes it's _universities_ that provide this shitty level of training.

    7. Re:Hard/weak references for event handlers by bidule · · Score: 1

      Weak references also incur the overhead of a check on every call to ensure the object hasn't been cleaned up. Not so. At least for languages other than CLR. Weak reference cleanup can be done by a "will" attached to the "dying" object. I have seen that in some dialect of Scheme, namely Gambit-C.
      --
      ID: the nose did not occur naturally, how would we wear glasses otherwise? (apologies to Voltaire)
    8. Re:Hard/weak references for event handlers by tgd · · Score: 1

      At the CPU level, how is that implemented? If you have something other than a jump instruction, you are incurring overhead. The CPU doesn't have a "jump if not set" instruction, so unless the teardown of the object physically went and altered code in memory, you'd still be doing a lookup or test at jump to ensure the weak reference is still valid.

      I'd hazard a guess that its good that 9/10 engineers don't know what a weak reference is because 9/10 of those who do have no idea what the use of them leads to. (In the case of Java, I've seen people using them who had no idea what effect their use has on garbage collection priorities, for example.)

      In the case of wiring up an event system, you'd want the event registration to hold the object the vast majority of the time because you want it to be deterministic about when the event stops firing to that code -- "well, it'll get picked up as long as the garbage collector hasn't cleaned up the object" is a lousy model. In the case of the original post, extend the object with IDisposable and implement a dispose method to unregister the object. Smack anyone upside the head who doesn't know to use the "using" keyword.

    9. Re:Hard/weak references for event handlers by bidule · · Score: 1

      Erm. "check on every call" vs "check on every kill". Which is more efficient OMNSHO.

      --
      ID: the nose did not occur naturally, how would we wear glasses otherwise? (apologies to Voltaire)
    10. Re:Hard/weak references for event handlers by tgd · · Score: 1

      I don't think you're following me.

      In memory you have an object. You have another n objects holding a weak reference to it. You garbage collect that object. Are you suggesting walking every reference to every method jump or inlined member access is a better implementation of weak references than doing a test? Even ignoring how you do that across process spaces (since .NET objects can reference events via remoting), how would you get around the fact that once the code has been optimized into native code, you can't change it again?

      I don't know if we're talking past each other or if you really don't understand how compilers (and a computer in general) works down at the metal. Give a specific example of what you're talking about...

    11. Re:Hard/weak references for event handlers by bidule · · Score: 1

      Are you suggesting walking every reference to every method jump or inlined member access is a better implementation of weak references than doing a test?

      I don't know if we're talking past each other or if you really don't understand how compilers (and a computer in general) works down at the metal. Give a specific example of what you're talking about... That's a very inefficient way to do that.

      I suggest you read section 10.2 of the Gambit-C documentation and understand how it works. I am surprised you didn't look at that before replying.

      You can also read the source-code for further enlightenment, but I'm not keen on reading bare-metal VM code. I know enough to trust the implementer's decision.

      --
      ID: the nose did not occur naturally, how would we wear glasses otherwise? (apologies to Voltaire)
    12. Re:Hard/weak references for event handlers by Anonymous Coward · · Score: 0

      "Weak references also incur the overhead of a check on every call to ensure the object hasn't been cleaned up."

      If that miniscule amount of overhead presents a problem, the developer should probably rethink the choice of a managed/garbage collected language.

      "This was sloppy, poorly tested code. The engineers on it made a mistake and caught it too late. It happens."

      Quite right!

  21. Re:As a C kernel programmer... by MacDaffy · · Score: 1

    I'll do the same and when people ask me what language they should use, I'll answer "Pascal."

  22. Re:As a C kernel programmer... by aproposofwhat · · Score: 1
    Yes, but if you spend your time coding in C, you learn (over time, admittedly) to take care to manage resources properly.

    Garbage collection invites laziness and mistakes, and is generally a bad thing.

    :P

    --
    One swallow does not a fellatrix make
  23. Re:Friends do not let Friends use Windows and Driv by Bob54321 · · Score: 4, Funny

    blue screams of death
    Is that a snuff film?
    --
    :(){ :|:& };:
  24. Nothing new here move along....OH Wait? by Anonymous Coward · · Score: 2, Funny

    Just like most windows machines it bogs down and starts crashing after about 40 minutes of hard use.

    1. Re:Nothing new here move along....OH Wait? by Anonymous Coward · · Score: 0

      Wow, another /. anti-Windows comment. !Hilarious as usual.

    2. Re:Nothing new here move along....OH Wait? by Anonymous Coward · · Score: 0

      another /. anti-Windows comment. !Hilarious as usual.

      If you don't like it, leave. anti-Windows comments have been with /. since the beginning.

  25. Re:As a C kernel programmer... by owlstead · · Score: 2

    In C#, the problem manifests itself as a memory leak. In C/C++ however, you would have freed the memory even while the listeners were still active. Now you have a reference to previously freed memory. I know what I would prefer. The only advantage is that - maybe - the C/C++ error would show up earlier, but the form of the manifestation might vary.

  26. Re:As a C kernel programmer... by cyber-vandal · · Score: 4, Funny

    That's why there are no memory leaks in C/C++ code [/sarcasm]

  27. Re:As a C kernel programmer... by maxwell+demon · · Score: 2, Insightful

    As user of programs written in GCed languages, in my experience usually they are bad memory hogs. And don't tell me that memory is cheap. People constantly forget that we are not any more in the days of DOS, where there was essentially only one program running at any time.

    --
    The Tao of math: The numbers you can count are not the real numbers.
  28. The other other problem here by Dachannien · · Score: 1

    There's one other huge huge glaring problem here. You have a system with real-world dangerous consequences that is dependent upon the continued proper operation of the software. When the software fails, the hardware apparently has no safe failure mode. This is a serious no-no in system design where improper operation of the hardware could create a hazard.

    It's easy to solve. The hardware should be designed with a watchdog timer that, if it ever expires without being reset, triggers a failsafe mode such as releasing the throttle and applying the brakes. Each mission-critical thread should be required to regularly notify a watchdog thread that it is still running, and the watchdog thread sends the watchdog reset signal to the hardware if all of the mission-critical threads are still running. If any thread exits inappropriately, enters an infinite loop, or otherwise stops being able to respond at an acceptable rate, the watchdog timer times out, and the vehicle stops.

    I realize that there is a manual system for stopping these vehicles if something goes awry, but as several teams found out the hard way, safety is absolutely paramount. Belt-and-suspenders is the way to go.

  29. C#? by symbolset · · Score: 1

    Why not SNOBOL?

    --
    Help stamp out iliturcy.
  30. C# does have direct memory pointers by alancjohnson · · Score: 1

    C# does have the facility to use direct memory pointers. The memory these pointers point to is never garbage collected. They are mostly used when access to unmanaged code's object is required i.e com and dcom.

    Not saying they were using these, but pointing out that the .net garbage collector doesn't clean everything.

  31. Stupid slashvertisement by Alkonaut · · Score: 1


    Lots of bashing about their design decision to use C#, about C# in general and so on. Their decision to use C# seems perfectly logical. Using a high level language to me seems like the ideal choice when writing complex control code. Perhaps a functional language could be even better. .NET will allow you to even mix languages as much as you want.
    I would have used a modern high level language (java, c# or a specialized language) for the high level control, and I assume that the lower level code device driver and control was written in, for example, c. Makes perfect sense. The fact that the code is described as containing only 10k lines of code just makes the point even more clear. Use the right tool for the job. Use several tools if you need to.



    The crash they experienced was because they didn't pay attention to their references properly. Garbage collection isn't any more magic than manual memory management. If you are sloppy the program will fail. The CLR worked exactly like it is supposed to. Unfortunately the fact that having an event handler on an object means that you are referencing it, is sometimes overlooked. If they had been as sloppy while using c/c++, they would have gotten some other problem instead, but the program would have crashed all the same. All this (slashvertisement!) shows is that doing memory profiling and long test runs is important, regardless of which language you have used.

    1. Re:Stupid slashvertisement by Anonymous Coward · · Score: 0

      You'd think that, but that's because you're a software developer. Any OS you can run C# on would probably not be a good choice for this system, though I can see using Linux for ease of development. Ideally though, a vehicle control system should have real-time capabilites and excellent fail-safe capabilities. AFAIK, that means no Windows and no C#.
      The fact that a simple memory leak caused the program "slow down until the car just simply stopped responding" just makes the point even more clear. That's not the right tool for the job. If they had been somewhat competent and knowledgeable about control systems, a program crash wouldn't have been a fatal error.

  32. Re:As a C kernel programmer... by toad3k · · Score: 1

    Well the program would have crashed. And they would have known where the problem was instantly instead of requiring a debugger.

    Also, what is the point of having an explicit delete if C# just ignores it? This is asked by a person who has never used C#. If I say to delete something, delete it. The program should halt if I try to use an object that has been deleted, or at least it should halt during the next gc when it discovers something has a pointer to it.

  33. don't these kids learn anything anymore? by m2943 · · Score: 5, Interesting

    (1) You are supposed to test your software.

    (2) You are particularly supposed to test your software if you send $200k and 1 ton of hardware careening through the street on autonomous real-time control.

    (3) Garbage collectors do not prevent memory leaks.

    (4) Garbage collected systems can be good for building real-time systems, but you need a real-time garbage collector or you need to treat the system as if it didn't have a garbage collector at all.

    What "ruined their chances" was not that they overlooked a memory leak, what ruined their chances was that they didn't know what they were doing.

    1. Re:don't these kids learn anything anymore? by MajorCatastrophe · · Score: 2, Insightful

      What "ruined their chances" was not that they overlooked a memory leak, what ruined their chances was that they didn't know what they were doing.

      Whereas code written by people who "know what they're doing" has zero bugs - ever. Right. And to assert that they didn't test their software is ludicrous.

    2. Re:don't these kids learn anything anymore? by ScrewMaster · · Score: 1

      Yes, but experienced programmers tend not to make obvious mistakes, because they've already made those mistakes at some point in the past. That's why they qualify as experienced. That also means that the seasoned types tend not to have obvious, glaring bugs but the more subtle, hard to find kind. On the other hand, these guys had a major systems failure ... every forty minutes the car's processor would crash. That's not subtle, nor is rebooting the system at fixed intervals a valid "solution."

      --
      The higher the technology, the sharper that two-edged sword.
    3. Re:don't these kids learn anything anymore? by porpnorber · · Score: 1

      As a programmer I'm inclined to agree with you, but as someone who has been involved in the 'academic mega-demo' business myself, I have great sympathy for these guys. In my case I didn't get burned, but my boss got on the plane to go to the conference where he did a big showcase demo of my work only four hours after it ran for the first time. I think I got in another twelve hours of testing before showtime, basically while he was in transit. The demo itself involved the code running constantly for an hour, twice, in front of a large audience, on national TV no less, with no margin for error.

      Does this mean I am a moron?

      Nope, it means that I had absolutely no say in the schedule.

      Since it worked, I was hailed as the messiah.

      One part engineering, three parts sweat and six parts pure dumb luck, is more like my analysis.

      See, what happens is, someone else sets the date. The real go/no go line is several months in advance of this date. The go decision is made (usually by management, often without detailed consultation with the programmers), the day arrives, and it kind of works, but you're not really ready. Not quite. Your choice: pull out and definitely have egg on your face, or go for it and maybe have egg.

      So you roll the dice.

      This was not one of those space shuttle situations where someone was going to die; the contest organisers knew that a ton of self-directed research-grade steel is a dangerous thing, and took the necessary precautions. So the decision to try it anyway was correct.

      Maybe, as programmers, they knew what they were doing; maybe they did not. We are simply not in a position to judge. What we have seen here is simply that a public trial is a public test, and a test is a test is a test.

    4. Re:don't these kids learn anything anymore? by chrisb33 · · Score: 1

      Your choice: pull out and definitely have egg on your face, or go for it and maybe have egg. As someone on Princeton's team, I can definitely confirm that this was the case, for both the 2005 and 2007 challenges. The DARPA competition is an extracurricular activity we participate in on top of being full-time students, so our available time for writing and testing code is always an order of magnitude smaller than we would like. There are very stringent safety regulations set down by DARPA, so putting something not fully tested in the competition was unlikely to be a danger to humans (there is a redundant emergency braking system that operates mechanically, independently from the computers).

      P.S. If you're interested in what we were working on for this year's challenge, check out our video from the summer or other videos on our website

      P.P.S. Red Gate (who wrote this article) has been a great sponsor of ours, but I agree that it's unfortunate that our Slashdot debut comes in the form of a slashvertisement rather than a technical paper.
    5. Re:don't these kids learn anything anymore? by porpnorber · · Score: 1

      Yeah, I suspected as much. At McGill, we used to do the Robocup thing, with the Aibos, on that kind of basis. Less gasoline and steel, but still lots of fun and confusion.

    6. Re:don't these kids learn anything anymore? by m2943 · · Score: 1

      Whereas code written by people who "know what they're doing" has zero bugs - ever. Right.

      You're hallucinating something I didn't say.

      But well tested code doesn't have these kinds of blatant and stupid bugs.

      And to assert that they didn't test their software is ludicrous.

      It sounds to me you don't even know what software testing is, because if you did, you'd know that they didn't test their software.

  34. Re:As a C kernel programmer... by toad3k · · Score: 1

    Edit: Nevermind, I should have read further down the page before I commented. I guess my language biases are showing.

  35. Ahahaha! by 19thNervousBreakdown · · Score: 2, Interesting

    This kind of thing makes me so happy. Sure, it's not really a bug in C#, but this is even better, a perfect demonstration of how GC does next to nothing to prevent this type of bug, and instead fools people into complacency while making the bug much more subtle.

    In my opinion there is a proper language level for nearly any task. For kernel programming, drivers, or RT stuff, C. User-level stuff is usually better in C++. Well, I'm a big fan of C++ and more comfortable there so I'll usually extend its range down to some lower-level work and sometimes I'll bang out a quick-and-dirty app or script type thing (lots of user input parsing and other things C++ isn't great at) in it too, even if it could be done better (yes, better as in higher quality) or faster in another language.

    Anyway, although I could be making incredibly wrong assumptions about the nature of the problem, I'm pretty sure that C# wasn't the right language for the job. C# very nicely occupies the space between C++ level languages and scripting languages, but for a problem that involves probably no parsing whatsoever (it shouldn't, anyway), needs to be perfectly stable (in my experience GC apps are buggier, I'm not going to go off on that tangent now and explain, but it's been my experience), and have as deterministic runtime as possible, it's C or a subset of C++ (little to no STL) all the way. This paragraph was brought to you by Lisp.

    This problem was caused by, I'm going to go out on a limb here and say the wrong language choice. If this was C/C++, there would have been a segfault (easy to debug--usually) or the old reference wouldn't have mattered at all. C#'s real strong point, its huge and well-integrated library, probably didn't help them out very much.

    Every programmer who wants to call themselves a real programmer should learn as many languages in as wide a range as possible. Sure, have favorites, but that should mean trying to work in your language's realm, not extending it way beyond its range.

    --
    <xml><I><am><so><damn>Web 2.0</damn></so></am></I></xml>
    1. Re:Ahahaha! by rbanffy · · Score: 1

      +1 insightful for you, but, since I am out of modpoints, I will comment a bit.

      While the automatic garbage collection did nothing to save those guys, relying on an unclaimed pointer is something very dangerous to do, even when in pre-release stages. Specially dangerous when you are talking about a 1 ton, 200 hp robot that becomes unresponsive after about an hour running.

      Complaining about how garbage collection made their bug all the more subtle is to miss the point a bit - the program was wrong and whatever language they used, it would be just as wrong.

      If C (and I love C) can be described as a low-level language with some high-level features added on, C++ can be described as C with some nice syntactic sugar (//, declarations anywhere) and an object-like system afterthought glued to it. It took me years to even learn C++ because of the yuck factor from being introduced to OOP with Smalltalk.

      I agree they did, indeed, program in the wrong language, but I would not recommend something as low-level as C or C++ or even C# (or Java) for this job. I would recommend them doing it in the highest level language available (and, if the highest level available for them is C#, to make something more adequate available ASAP) and to build a domain-specific language on top of that.

      By having to focus on potential collision event handlers that could be partially freed (and, in effect, lost in memory) they did make a good point that they were looking at a far lower abstraction level than they perhaps should.

    2. Re:Ahahaha! by Jugalator · · Score: 1

      If this was C/C++, there would have been a segfault (easy to debug--usually) or the old reference wouldn't have mattered at all.

      Wait... If this was C/C++, wouldn't the same thing have happened?

      In this case they would also not have delete'd the allocated objects because they were never to be deleted according to their bugged object detection code.

      If they would have deleted things already deleted, yes, then they'd get a debuggable segfault.

      But in that case (which wasn't what happened), C# would have also crapped out with something like an ObjectDisposedException and accompanying stack trace.
      --
      Beware: In C++, your friends can see your privates!
    3. Re:Ahahaha! by 19thNervousBreakdown · · Score: 1

      No, in C++ they would have had containers or references/pointers to the objects. They explicitly deleted the objects in their C# code--or so they thought. In C++ they would have actually deleted the object, and left a dangling pointer, if they made the exact same mistake. When they tried to call that, they'd either get a segfault, or depending on their code and memory manager, a pointer to the wrong object of the same type--which would be pretty subtle--or a pointer to the wrong type, leading again to an almost certain segfault.

      Also, when you delete in C++, standard practice is to set the pointer to 0, which is safe to call delete on.

      --
      <xml><I><am><so><damn>Web 2.0</damn></so></am></I></xml>
    4. Re:Ahahaha! by 19thNervousBreakdown · · Score: 1

      I have to respectfully disagree, and here's why: Their abstraction leaked on them. It's a soft abstraction, and it while doesn't explicitly guarantee that objects are "fire and forget" it implies it really, really hard, the same as PHP, Ruby, Bash and the like imply that you don't have to worry about type safety. The problem is, they're not, you do, and C# is so incredibly complex and abstracted it's nearly impossible to know what's actually happening.

      On a hyperbolic note that's sure to get me flamed, I'm not sure exactly what it is, but every program I've ever interacted with that's written in C# has been poor quality, even the ones written by "professional" programmers. They have weird UI stuff that doesn't work, memory leaks, crashes, you name it. What causes it exactly, I couldn't say, but I know I wouldn't want a .NET pacemaker, no matter how much it won't segfault when it's parsing a string.

      --
      <xml><I><am><so><damn>Web 2.0</damn></so></am></I></xml>
    5. Re:Ahahaha! by gbjbaanb · · Score: 2, Insightful

      No flame here - I think the issues you describe with C# programmers are to do with the age of the language, no-ones really an expert in it as although its been around a while, its only recently people have started coding 'proper' applications in it.

      Its my experience with it that apps written using it are poor too though. I've been headhunted twice now by companies that rewrote their old apps in this cool, new language only to find that it performed so badly they couldn't sell it. (I used to be a performance engineer/troubleshooter at my last job).

      And its not just C#, its the .NET thing in its entirety. I had a little task to do once that involved taking a dozen DB columns and merging them into 1. No problem, I thought I'd write it in managed C++ (as it was a throwaway oneoff task), and it was easy to write and ran ok on my test DB of 300 rows. When I ran it on the live DB, I calculated it would have taken 13 hours to run through all the half-million rows they had (even after doing every optimisation trick I knew, and cutting the code to the minimum). So I rewrote it in "old-fashioned" OLE-DB and it took 10 minutes.

      I'm not a fan of .NET either.

    6. Re:Ahahaha! by Xtravar · · Score: 1

      Ugh, you expect people who don't understand garbage collection to understand C++ and stack vs heap allocated objects?

      I used to be big on C++, but it tends to encourage more wasted time trying to do the perfect OO model, and most libraries are written in C anyway, which will often make you inclined to wrap them, which never works out very well and is a waste of time...

      --
      Buckle your ROFL belt, we're in for some LOLs.
    7. Re:Ahahaha! by Anonymous Coward · · Score: 0

      I'm not a fan of shitty programmers either.

      There, fixed that for ya.

      Both you and the GP keep missing the point, over and over and over. The GP's parent got the point: The problem here isn't the tool. It's that either the project used the wrong programmers for the job and/or the programmers used the wrong tool for the job. If the people running the project decided they had the exact right programmers for the job, the programmers choose too low-level a language/platform for their skillset. Since most of us would be suspicious of using a non-real-time garbage-collected environment for this particular type of project (as much as I quite happily do work in one 40 hours a week), I dare say that the project had the wrong programmers for the job and that their choice of language/platform was only a side-effect of being the wrong programmers for the job.

    8. Re:Ahahaha! by clayne · · Score: 0

      Would you trust a multi-ton fuel-laden MOVING machine if it's core controller was coded in C or C#?

      C

      .

    9. Re:Ahahaha! by mad.frog · · Score: 0, Troll

      a perfect demonstration of how GC does next to nothing to prevent this type of bug

      I think you meant to say, a perfect demonstration of how C#/CLR's implementation of GC has inadequate facilities to detect and prevent this type of bug...

    10. Re:Ahahaha! by Anonymous Coward · · Score: 0

      I dunno. I can see coding their app in C++ for the performance, but I don't think that's really the best choice. You need a language that not only is a good language, but one that the developers you actually have can actually use effectively. If the whole team is Bell Labs alumni expert developers, then hells yeah C++. But if these guys had the problems they had, I'll bet they would have had worse problems in C++.

      For anything AI-like I'd prefer to code in Python, as long as the performance is good enough for the task. Trying to drive a car is a pretty AI sort of problem. With a good design I'll bet Python would be plenty performant for this problem. If it's too slow, pre-process a bit: have a couple of dedicated processors that take the video input and figure out what looks like objects, and then spoon-feed the objects to another processor that decides where to drive. I'd rather work on a system like that than a big monolithic system written in a lower-level language than Python.

      Ruby fans would of course prefer Ruby. It's even slower than Python, but not by that much, and if Python could be made to work so could Ruby; it's a matter of preference, and I just prefer Python.

      People used to tout LISP as the solution for all AI problems; it's certainly a powerful language, but most developers don't seem to prefer it, so if you use it you are limiting your ability to find more developers to work on it in future.

    11. Re:Ahahaha! by mad.frog · · Score: 1

      WTF? How the hell was the parent comment a Troll?

      Want to disagree with my assertion, fine, post a response saying how I'm wrong. But there was nothing trollish in my post; it was posting a correction to what I see as a misstatement by GP.

    12. Re:Ahahaha! by zoips · · Score: 1

      As had been referenced a nauseatingly large number of times prior to your post, they merely need to use a free CLR memory profiler provided by Microsoft and they would have found their bug. The tools were already there, they just didn't use them. Hence, as your post is annoyingly anti-MS rhetoric with no value, it is marked a troll.

      Tada!

  36. Another similar Problem... by Raven737 · · Score: 4, Informative

    Well the Event Subscribed 'problem' is well known and makes sense if you think about it. I mean subscribing to an Event means placing a pointer to a delegate of a method in a event subscriber list.. when someone raises that event then each delegate in the list is invoked... so basically it is an implicit reference and hence can prevent the it from being marked for garbage collection.

    However, i had another memory 'leak' problem where the Garbage Collector simply didn't collect in time which caused my application to use more and more memory until it reached the system limit and crashed... i found that simply calling
    GC.Collect();
    GC.GetTotalMemory(true);// (the true 'forces' collection ;)
    once would fix this problem... i though i needed to call it every minute or so... but when calling just once it did SOMETHING that prevented this problem from occurring again.. no idea exactly what.. but it works :)

    1. Re:Another similar Problem... by Anonymous Coward · · Score: 0

      once would fix this problem... i though i needed to call it every minute or so... but when calling just once it did SOMETHING that prevented this problem from occurring again.. no idea exactly what.. but it works :) You are a danger to yourself and everyone around you. NEVER work on software that is connected to any kind of hardware that moves, unless you're prepared to ride in it yourself :-)

      Seriously though, this is the problem with the higher level languages, after a while you become reliant on them and their libraries, all of which purport to do something, but you're never quite sure whether its doing it exactly as described in the documentation.
    2. Re:Another similar Problem... by TummyX · · Score: 1

      It is extremely unlikely that you would run out of memory before the GC collected (where the fix is to call GC.Collect).

      The poblem sounds more like you're running out of a non-memory system resource such as file handles. Your call to GC.Collect and GC.GetTotalMemory is most likely causing the a collect and then a finalizer run that frees up file handles. Make sure you call Dispose on objects that implement IDisposable after you've finished using them (or use the C# using statement to automatically dispose objects after a code block has finished).

    3. Re:Another similar Problem... by Tolkien · · Score: 1

      All that does is hide the problem, it doesn't fix it. It's good that you use this method as a temporary fix, but you shouldn't stop looking for the source problem.

    4. Re:Another similar Problem... by Johnno74 · · Score: 1

      Dude your problem is not directly memory related. Somewhere you are indirectly referencing an unmanaged resource, and classes that wrap unmanaged resources (such as database connections) typically only free their resources on a finalize - so on the 1st pass of the GC the object is marked for finalization, and on the 2nd pass the finalize code runs and frees the resource (or memory)
      Classes that have a finalize method implement IDisposable. you *must* call dispose before you set the object to null or let it fall out of scope. This will tell the class to free its resources immediately... otherwise it doesn't free them until finalize runs, much much later.

      I've had exactly the same problem with database connections (the DB would run out of connections when the site was VERY busy, but under normal use they would eventually close themselves) and also with GDI objects such as bitmaps, fonts and brushes. The symptom of that one was asp.net killing the process because it used too much memory when the site was busy.

      Both times I found all the code that used objects that implemented dispose, and called dispose as soon as I can. no more problems at all. The asp.net app using GDI also used less than half the memory it had been as well.

    5. Re:Another similar Problem... by ozphx · · Score: 1

      As the other guys said...

      But also DO NOT CALL GC.Collect(). Its bad for your health. It forces objects that survive collection up through the generations, making GC sweeps take longer and the whole system runs inefficiently.

      --
      3laws: No freebies, no backsies, GTFO.
  37. Re:As a C kernel programmer... by KDR_11k · · Score: 1

    Yes but errors always happen.

    --
    Justice is the sheep getting arrested while an impartial judge declares the vote void.
  38. Why allocate memory on the fly? by metalmario · · Score: 1

    Instead of doing lots of news and deletes on the fly, why not allocate enough memory when the program starts and use that instead? That way you won't fragment your memory pool either, or have those age long garbage collection sessions. Anyway, the topic of today is bad programming, move on, nothing to see here.

    1. Re:Why allocate memory on the fly? by Lonewolf666 · · Score: 1

      On top of that, memory allocation/deallocation is not the fastest operation under Windows in my experience (Delphi application in Windows 2000). That application had one window in which a cross-section though a two-dimensional map was displayed, and the angle of that cross-section could be rotated with the mouse.
      Well, people were complaining that it was slow and choppy. Indeed, it would update on a Pentium 4/1.7 GHz with maybe 10 FPS. Further investigation showed that for each painting of the cross-section, a buffer of a few hundred kByte was allocated and subsequently freed.

      After modifying the application to "allocate once when showing the window, then re-use that buffer", rotating the angle of the cross-section was MUCH faster. While I did not take exact measurements, I estimate that the memory allocate/deallocate took at least half of the processor time in the original version. That would be 50 milliseconds or more.

      --
      C - the footgun of programming languages
    2. Re:Why allocate memory on the fly? by Anonymous Coward · · Score: 0

      The memory management system in .Net doesn't use the regular Windows memory management. In fact, it does a lot of what you describe, where it obtains a block of physical memory and attempts to use that as much as possible before going and getting more.

      In fact, allocating and freeing object memory is one of the fastest operations you're going to see in .Net, they spent a *long* time optimizing it since they new they would get hammered on the performance of their GC.

      Since you've obviously never looked in to it: http://msdn.microsoft.com/msdnmag/issues/1100/GCI/

      Feel free to educate yourself. Then again, this is Slashdot, so slamming MS for no reason (there are plenty of good reasons, use those) seems to be par for the course.

    3. Re:Why allocate memory on the fly? by gbjbaanb · · Score: 1

      That's true of every program, allocating memory has always been a relatively slow operation. For speed, one good trick is to use a custom allocator - create yourself a chunk of memory that holds blocks of fixed sizes. (eg think of it like an array of 1 byte), then create another for 2byte blocks etc. When you allocate, just take the next block off the appropriate 'array'. Its very fast, and allows you to reuse the memory very efficiently (as the 'arrays' can't get fragmented)

      C# managed heap does something similar, so does the COM heap.

    4. Re:Why allocate memory on the fly? by Lonewolf666 · · Score: 1
      It's not Windows doing the memory allocation, it's the Delphi MM.
      Partly true, the Delphi MM gets memory in relative large blocks from Windows and does its own suballocation. Quote from an article about Delphi 2006 (http://dn.codegear.com/article/33416#27ImplementationDetails):

      The medium block manager obtains memory from the OS in 1.25MB chunks. These chunks are called "medium block pools" and are subdivided into medium blocks as the application requests them.
      Our application was in Delphi 6 BTW. Anyway, I don't think Borland would have bothered using their own MM if it wasn't better than going to the WinAPI for everything. Thus I presume memory allocation through the Windows API would have been even slower ;-)

      Only a moron would allocate and deallocate the same sized buffer on every mouse move triggered paint
      Sure, and we did change it once we noticed. Who the original moron that wrote that piece of code was is no longer known.
      --
      C - the footgun of programming languages
    5. Re:Why allocate memory on the fly? by Lonewolf666 · · Score: 1

      Thanks for the link. But that particular application was (and still is) an old-fashioned Delphi 6 application. .NET doesn't have anything to do with it.

      Maybe .NET would have been better in that situation, but the company I work for had its own problems in the past with .NET 1.1 (mostly installation issues in the field).

      I'd rather optimize some more routines for sparing use of memory allocation than try to find the reason for intermittent installation failures of a .NET environment. After all, we have the source code for our own stuff so we can debug it :-)

      --
      C - the footgun of programming languages
    6. Re:Why allocate memory on the fly? by petermgreen · · Score: 1

      Usually when doing that you would make your smallest block the size of a pointer, otherwise it is rather hard to track free blocks.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    7. Re:Why allocate memory on the fly? by gbjbaanb · · Score: 1

      Full implementation was left as an exercise for the reader :) A bitmap of free blocks works very well. It really comes in to its own when you have allocators that store 16-byte, 32-byte etc blocks. Then allocate the best fit string/object in there. If you use the lowest level interlocked functions to set the bitmap flag to show the block is used, then you have the ultimate in performance.

  39. One word by Anonymous Coward · · Score: 0

    Spit!

    Blatant slashvertisment and also a misleading title trying to blame stupid programmers' mistakes on Microsoft and C#. Spit! Spit! And... spit!

  40. A managed leak by Caesar+Tjalbo · · Score: 0

    It was the closest thing to a memory leak that you can have in a managed language.
    That's one way of putting it, I'd say if your code drives off in a car it's hardly a "leak" and certainly not "managed".
    --
    "I'm not much interested in interoperability. I want substitutability. I want to be able to throw your software out."
  41. In other words by Anonymous Coward · · Score: 0

    After being convinced by salesmen telling it will solve all your problems, you spend money on a proprietary development system/language coming from a company well known for anticompetitive practices and tied to a closed platform. Then, when your code bites you in the ass, someone tells you another proprietary software would have solved all problems, and you're forced to waste more money. Sounds familiar?
    Of course it does! It's the L. Ron Hubbard way of doing business, applied to the IT field.

    No thanks, I'll stick with GCC: it's way more productive than the above stuff, unless one thinks productivity is just a matter of doing the same thing in two lines of code instead of five, regardless of performance, optimization, peer reviewing, being in control of what the software does, etc.

  42. It a coding error. But C# dumbs down coders. by 140Mandak262Jamuna · · Score: 0, Troll

    Looks like they can't directly blame C# for not releasing memory while they are still holding references to the supposedly deletable objects. But I have seen appallingly low understanding of OO principles among the candidates I interview who had grown up in C# environment. My big grouse is that even in C++ Visual Studio and .NET IDEs inhibit a big "picture" understanding of large and complex code. The number of times I had to berate newbies for including afx.h in a "platform independent" base class headers ...

    --
    sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
  43. Re:As a C kernel programmer... by ozzee · · Score: 0, Offtopic

    That's why there are no memory leaks in C/C++ code

    The last few large projects I have worked on with C++ had no issues with memory leaks on product release and these were servers that run for months. Proper use of smart pointers and correctly designed classes is not that hard. The last Java based product I worked on had all kinds of leaks and issues.

  44. Swing by Tim+Ward · · Score: 3, Informative

    They can't have had anyone on the team with experience of coding for Swing in Java then - you get these all the time, sometimes hanging tens of megabytes of unwanted GUI objects off a single listener registration, and learn how to spot and fix them.

    1. Re:Swing by Anonymous Coward · · Score: 1, Interesting

      Unfortunately, Sun also get these occasionally. While I writing my dissertation app, I was wondering why it took 2GB of ram to iterate through 80MB of jpegs and generate thumbnails of them....

      The resizing function was non-synchronous and had a callback to let your GUI know when the resizing was done. Turns out it was never removing the pointer to the uncompressed image internally after passing it out to the callback function. This bug has long-since been fixed, but it just goes to show that everyone makes this kind of mistake sometimes. It took quite a while to track that down, as the memory leak wasn't in my code, but eventually I fixed it by using a blocking resize function.

  45. Designed for safety ? by Ihlosi · · Score: 2, Insightful
    usually with the gas pedal down, and would just drive off into the bush until we pulled the plug.

    Yikes. So these guys have the smarts to make a computer drive a car on its own, but managed to forget some basic safety mechanisms such as a watchdog and other failsafe mechanisms ?

    Geez guys - real world engineering 101: Do not let a computer control anything that might have a remote chance of harming someone without appropriate safety mechanisms.

    1. Re:Designed for safety ? by dzfoo · · Score: 1

      Its worse than that! According to the article, they were aware of this "leak" bogging down the system, which came up during testing; and programmed in a timer to restart the application after 40 minutes -- without truly understanding the nature of the issue, or its safety implications.

      Then, during the actual course run, the system became unresponsive in about 28 minutes instead of the 40 that it took during testing, so the timer did not helped.

      No code profiler can fix incompetence like that. I am glad they did not win the challenge. If by chance their timer were set at, say, 20 minutes and it just happened to maintain the system usable during the desert run, it still remains a crap implementation, and winning would have defeated part of the purpose of the competition.

                  -dZ.

      --
      Carol vs. Ghost
      ...Can you save Christmas?
    2. Re:Designed for safety ? by chrisb33 · · Score: 1
      As someone on Princeton's team, I can tell you that we did have a failsafe mechanical braking system (independent of the the computers that could be messing up). Whenever the car was running without an operator, an pneumatic brake was controlled by radio - if the receiver ever lost signal (went out of range of the transmitter) or received a disable command, it would fire the pneumatic brake to stop the car regardless of whether or not the computers were responding to commands.

      Geez guys - real world engineering 101: Do not let a computer control anything that might have a remote chance of harming someone without appropriate safety mechanisms. Agreed. Believe me, the first test DARPA does at each stage of the competition is make sure that the emergency systems work.
    3. Re:Designed for safety ? by Anonymous Coward · · Score: 0

      "As someone on Princeton's team, I can tell you that we did have a failsafe mechanical braking system (independent of the the computers that could be messing up). Whenever the car was running without an operator, an pneumatic brake was controlled by radio - if the receiver ever lost signal (went out of range of the transmitter) or received a disable command, it would fire the pneumatic brake to stop the car regardless of whether or not the computers were responding to commands."

                  That's not the kind of failsafe the OP and I are talking about. It really should have a system such that, if the gas pedal controller doesn't receive a signal from the computer in a timely matter, it lets off the gas. Admittedly there's time constraints and all, but it would certainly look better in case of computer fault to have your vehicle come to a stop on it's own than to have it go out of control until a human hits the kill switch.

                It's too bad this memory leak offed your vehicle... good luck next year.

    4. Re:Designed for safety ? by chrisb33 · · Score: 1

      True, software failsafes would help us save face and should be implemented, but in terms of safety issues ("anything that might have a remote chance of harming someone") we were in the clear.

    5. Re:Designed for safety ? by Ihlosi · · Score: 1
      it would fire the pneumatic brake to stop the car regardless of whether or not the computers were responding to commands.

      Does it kill the engine, too ? I'm a control engineer, not a mechanical engineer, but I'd assume that either the transmission, the driveshaft or the engine wouldn't survive one system having the foot on the brake and the other system having the foot on the gas pedal for more than a few seconds (possibly longer than it takes someone to get there and shut it off manually).

    6. Re:Designed for safety ? by chrisb33 · · Score: 1

      Yes, it kills the engine and doesn't allow it to be restarted until the brake is released. This was always something we had to be aware of, since we relied on the engine to power the battery (and therefore all of our equipment) so if we left the system e-braked for a few minutes everything would lose power (good for safety, I suppose, but bad for testing).

  46. I think they just learnt something by driddint · · Score: 3, Informative
    They did do testing - (1) above - because they knew there was a problem that they could repeat. They just tried to pretend it wasn't happening.

    ... Because we didn't know why this problem kept appearing at 40 minutes, we decided to set a timer. After 40 minutes, we would stop the car and reboot the computer to restore the performance. ...

    They also didn't pick a very good hack because it didn't leave the car in a safe state when the software broke.

    Lack of practical experience I'd say. A few more events like that and they'll make decent devs one day.

  47. Repeat after me by nwbvt · · Score: 1

    Every half way decent programming language will allow you to leak memory.

    Its trivial to show this as long as the language supports some sort of array. Garbage collection is useful, but it does not save you from memory leaks. I don't know how many times I've told some retard JavaScript "programmer" that yes, they do have to be mindful of memory leaks even though their language has a garbage collector.

    --
    Mathematics is made of 50 percent formulas, 50 percent proofs, and 50 percent imagination.
  48. but did they end up buying the software?! by Anonymous Coward · · Score: 0

    I'm not convinced that the company got any cash out of the coders given it exposed the problem straight away...

  49. Holly Crap! Manslaughter 101 by MasterOfGoingFaster · · Score: 1

    From TFA:

    "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."

    Whatever issues the software guys had, the hardware control guys are the real story. They designed a machine that they KNEW would run out of control with potentially deadly results. If it had run over someone, these guys would surely be arrested for manslaughter. Now imagine they can't "pull the plug" because they dropped the remote control, AA batteries died, got out of range, etc. Now you have a out of control truck heading for that group of Boy Scout hikers, a highway or other contestants.

    Who the hell was supervising these students? I want to make sure I don't hire anyone from THAT school.

    --
    Place nail here >+
  50. yeah. sure. by Anonymous Coward · · Score: 0

    It is a poor carpenter that blames his tools.

  51. Ob. Eric Sink quote by MK_CSGuy · · Score: 1

    A nice quote from Eric Sink's Source Control HOWTO:

    Recently when I asked my fifth grade daughter what she had learned in school, she proudly informed me that "everyone in Korea eats kimchi at every meal, every day". In the world of a ten-year-old, things are simpler. Rules don't have exceptions. Generalizations always apply.

    This is how we learn. We understand the basic rules first and see the finer points later. First we learn that memory leaks are impossible in the CLR. Later, when our app consumes all available RAM, we learn more.

    1. Re:Ob. Eric Sink quote by gbjbaanb · · Score: 1

      First we learn that memory leaks are impossible in the CLR. Later, when our app consumes all available RAM, we learn that Microsoft's marketing department and all those MS bloggers who told us how useless reference counting was and that the GC was the perfect answer to all our memory problems, lied through their teeth to sell us the new visual studio.

  52. Hotfix from Tech Support! by Sun+Tzu · · Score: 1

    Ok, so the headline is bogus...

    But what a lost opportunity for a Reboot Fix, in the grand tradition of MSware throughout history. Just think, an automatic reboot for your robot car, plane, spaceship... and it just keeps going! (or, more properly, starts going again -- now, where was I?)

  53. Garbage collected languages are a poor idea by MORB · · Score: 1

    Those new, shiny languages like java and C# are often promoted as something magical that absolve developers entirely of memory management issues.

    The truth is that garbage collection are tuned based on heuristics that are not necessarily adapted to the workload of your particular program. But since it's designed and sold as a system to take memory management out of your hands, you can be left clueless as to what the fuck happens, and end up with problems even more complicated and obscure to solve than when you do manual or semi-manual memoetry management and something leaks.

    Give me C++ RAII any time along with reference counting smart pointers and I'm happy. Sure, circular references are a problem, but some people (among which Mr. Boehm) are working to include the concept of litter collection in the next C++ standard (basically a garbage collector that could be ran at a very low frequency and only intended to pick up the trash left by the smart pointers, ie circular references)

    1. Re:Garbage collected languages are a poor idea by Anonymous Coward · · Score: 0
      The reason that C++ programs leak worse than the Titanic is the lack of GC. Bad GC is better than no GC, and good GC is a wonderful thing. Your argument would only make sense if we lived in a world where C++ apps didn't keel over from OOM errors on a daily basis.

      Of course, any true garbage collector would just delete C++.

      TWW

  54. Ummm... by ta+bu+shi+da+yu · · Score: 1

    ... disagree. Yes, there was glitch they picked up with the way they dealt with the GC. But when they enter the car next year, using C#, they'll be able to get much further.

    Which means that the language did the job very nicely.

    Don't you get it? It's not the language, it's the programmer. I vaguely remember people saying that everything should be done in assembly instead of C or C++. Look where that got them. The truth is, any capable language used correctly can almost always do the job you need. C# is no exception.

    --
    XML is like violence. If it doesn't solve the problem, use more.
    1. Re:Ummm... by 19thNervousBreakdown · · Score: 3, Insightful

      It's the programmer and the language. Give the world's best carpenter a ball-peen hammer and ask him to build you a beautiful armoire, see what happens.

      You can say now that they'll be much further next year, but until then "Which means that the language did the job very nicely" should be "Which would mean that the language did the job very nicely." If you put in a reminder of some sort to come back and say I told you so, I'd be more than happy to eat my words if they continue using C# and place in the top 33%. Hell, I'd even concede that you might be right if they manage the top 50%.

      I say, however, that there is a right language for the job. Sure, there's overlap, but you don't implement your FFT in Perl when the problem is that you need the fastest FFT possible, you don't write a word-processor in assembly, and you don't write anything in Brainfuck even though they're all Turing-complete. Anyone who says you can do anything in any language is trying to justify using their favorite language for absolutely everything.

      --
      <xml><I><am><so><damn>Web 2.0</damn></so></am></I></xml>
    2. Re:Ummm... by ta+bu+shi+da+yu · · Score: 1

      True, your last sentence makes a lot of sense. Obviously nobody would write a word processor in assembly :-) Though with Brainfuck - I did say "capable"!

      However, in this case, the language wasn't inappropriate. It's pretty clear that the coders just didn't use standard profiling tools to determine where the problem was. That's not really a problem with the language, that's a problem with a bug in their code.

      --
      XML is like violence. If it doesn't solve the problem, use more.
  55. Re:The other other other problem here by mce · · Score: 1

    Even worse is the reaction of the developers when they found that after about 40 minutes of driving things became uncontrollable (without safe failure mode, as you point out). They just decide to reboot the system based on a mere timer without understanding what's going on or where the 40 minutes time frame originates. And on top of that they don't seem to mind that their reboot might occur at a critical moment as well, which not only does not address the original "accident waiting to happen", but introduces a second one as well! These people are dangerous and should never be let loose in an engineering environment at all.

  56. Reference counting by Megane · · Score: 2, Insightful

    I just read TFA and it doesn't give any details. My guess? I just checked, and C# apparently uses reference-count garbage collection. That means that an object will stay around until there are zero references to it. The best way to create an object that will never go away is to create a circular linked list, then delete the reference to the list. All the items refer to each other, but there is nothing else that references them. But any complicated data structure that can have circular references will leak memory.

    A mark-sweep garbage collector will catch this, but at the cost of interrupting the program temporarily to do GC. This isn't exactly friendly to real-time applications.

    So basically this looks like a classic noob blunder. Just because there is "automatic" garbage collection doesn't mean that you can turn your brain off.

    --
    #naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
    1. Re:Reference counting by noidentity · · Score: 2, Insightful

      I just checked, and C# apparently uses reference-count garbage collection.

      I highly doubt that. Got a link?

    2. Re:Reference counting by pete23 · · Score: 3, Informative

      I just checked, and C# apparently uses reference-count garbage collection. erm... no. the CLR implements a mark-sweep-compact generational GC pretty much like Java's.

      these don't have any problems with circular reference structures - if it can't be reached from a root and marked, it'll get collected.

      still just a blunder, as you say.

      this article should be binned - misleading title and nothing but a puff-piece for a profiler. i much prefer YourKit, incidentally:-)
    3. Re:Reference counting by Etrigoth · · Score: 5, Informative

      Actually, C# doesn't reference count at all, it 'Reference Traces' :)

      Please, let me explain; it's quite sad how often people don't get this ...
      .Net has its block of managed memory, called the Managed heap. It's separated into 3 'generations'. This heap has 2 areas, free space and reserved space, from top to bottom.

      When you allocate and object to the heap, by using the new command (object o = new object();) there is a set of rules? that have to be enforced:

      • Allocation occures in a contigious range of the freespace, that's as big as the size the clr determines the type to be.
      • The order of objects must be in the order of creation
      • There must be no gaps between objects
      • The oldest objects are in the lowest address space

      The GC manages Reference tracing, and this doesn't occur when the object goes out of scope, it actually happens when the Heap is full and you attempt to allocate a new object.

      In something called 'the sweep', the GC goes through each object in the heap to see if it's reachable. To do this it starts with so-called 'roots'. It then traces to see which objects are referenced by these roots.

      A root identifys a storage location, which referes to objects on the managed heap, or objects that are set to null. For example, all of an applications global and static objects are considered to be it's roots. (hence the reason that all C# apps have a static void main).

      When the sweep starts, it assumes that all objects are garbage. So for each root object, it builds up a graph of the objects that root references, and marks them as being live.
      However, if it finds an object that's already in the graph, it stops traversing that path. This is two (massively) increase performance by not scanning the same object twice, and more importantly, it stops you getting into an infinite loop by scanning a circular list.

      The pinch is, it prevent the circumstance that you mentioned!
      Because the strong reference to a linked circular list is gone, the circular list isn't attached to a root object, so it gets disposed. If you don't want it to get dropped, unless it theres a memory shortage, the C# GC also supports something called Weak References, but I'm not going to go into those here as it's headhurting :)

      So once all the roots have been checked and we've got a nice graph of all the objects that are referenced by the live parts of the application somehow, the second stage of GC happens.

      Any objects that haven't been touched by the walk are of course still marked as Garbage. The GC now walks up the heap linearly, looking for contigious groups of garbage which are now considered to be free space. The GC looks for the next live object and moves it to the start of this free space with a good old memcpy :) This ofcourse invalidates all the root pointers, so the GC then updates the points in the root objects.

      So now, we've got rid of all the garbage and our heap is pleasantly compacted; Take that Heap Fragmentation, Kerpow!!
      But, that's not all she wrote of course :)

      Now we're free'd and compacted, the 'nextObjPtr' is moved to the top of the heap. At this point the new object creation that triggered the collection is performed and the new object appears at the top of the heap.

      This is a dramatic over-simplification and I've not attempted to explain finalization or weak references, but it's still good to know this stuff, it helps us as .Net programmers to consider how to write our code properly :)
      The other thing I've not explained is how the Generations work:

      • We create a new object and the CLR realises that Gen0 is full and a sweep occurs.
      • Firstly, before the sweep and trash, Gen0 has the youngest objects that the GC has never seen.
      • Now that the sweep has finished, all the compacted obje
      --
      When we remember we are all mad, the mysteries disappear and life stands explained.
    4. Re:Reference counting by Trailer+Trash · · Score: 0

      So basically this looks like a classic noob blunder. Just because there is "automatic" garbage collection doesn't mean that you can turn your brain off.

      Um, you're talking about people who thought it reasonable to have a car driven by a program written in a Microsoft language running on a Microsoft operating system. I'm not sure when the brain was turned off, but apparently before the choice of programming platform was made.

      The "article" is just a poorly masqueraded advertisement, anyway.

    5. Re:Reference counting by chairthrower · · Score: 2, Interesting

      Can you show me any document that indicates that c# (CLR) objects use reference counting. I find it extremely odd that your comment is moderated insightful.

      MS used gc rather than reference counting in CLR to get around the problem of circular references so prevenlant in COM/ DCOM etc.

      Also this is a classic problem in c# - the event handler holds on to the reference - so you need a dispose() to handle exceptions and explicit removal of refereces. but having recently tried to do something similar in c++ using various combinations of boost::bind siglib and refernce counted pointers its not as a trivial problem to solve in any language.

      for those who say just use a weak reference when you need to for multicast delegate behaviour i would like to see their c++ template code they use to parameterise this kind of functionality. Really I am still looking for a good solution to good event handling in c++ that works well in multithreaded environments, and takes a reasonably modern approach to memory (ie RAII).

    6. Re:Reference counting by psmears · · Score: 1

      I just checked, and C# apparently uses reference-count garbage collection. That means that an object will stay around until there are zero references to it.

      No, it does use a mark-sweep garbage collector. This does present challenges to real-time applications; I imagine the GC is tunable to some extent (I know the Java one is)...

    7. Re:Reference counting by StormReaver · · Score: 1

      "So basically this looks like a classic noob blunder. Just because there is "automatic" garbage collection doesn't mean that you can turn your brain off."

      Having programmed in C, C++, and Java for several years each (and many other languages, but these are the three most relevant ones), I've concluded that the last major improvement in general memory management that solved more problems than it caused was the move from malloc()/free() to new/delete. Actually, Qt's auto-deletion of objects via parent/child relationships is a close second. Garbage collection seemed nice in theory, but it was just a lateral move from new/delete with a slight backwards motion.

      The complicated overhead needed to implement garbage collection systems eliminates all of the theoretical benefits it is supposed to provide. It not only has diminishing returns over explicit memory management via new/delete, it has negative returns in the false sense of security it gives to programmers. It doesn't cause bad programming practices, but it certainly encourages them. It also allows for the exact same problems it was supposed to solve, with the only difference being how it arrives there.

    8. Re:Reference counting by Anonymous Coward · · Score: 0

      Given that they think Microsoft products are suitable for use in something as critical as an autopilot system, it's hardly surprising they'd make such a n00b error. Quite obviously they don't know what they're doing.

    9. Re:Reference counting by lukatmyshu · · Score: 1

      mark and sweep would not have caught this. The obstacle object was still reachable (since it was reachable from the Event Subscriber object, which would definitely be reachable). You would be correct if the problem was that the obstacle object held a reference to itself.

    10. Re:Reference counting by Anonymous Coward · · Score: 0

      The problem didn't lie with the language or the OS.

    11. Re:Reference counting by Anonymous Coward · · Score: 0

      Actually, .NET (and therefore C#) uses a mark-sweep garbage collector. You can safely create circular-references in .NET and it'll all be garbage collected when no one references that blob of data.

    12. Re:Reference counting by Anonymous Coward · · Score: 0

      I just checked, and C# apparently uses reference-count garbage collection

      Check again, you misinformed FUD-spreader. And try a little bit next time. Everybody knows that mark-and-sweep is where it's at.

  57. weak references by edxwelch · · Score: 2, Informative

    Unintentional object retention. I think that is the official name of the problem. It occurs with managed languges. You have a big application with hunderts of objects referencing each other, it's inevidable that you will forget to null out a reference somewhere. (and by the way this is not exclusively a problem of event handlers, it can happen anywhere).
    The solution it to use weak references.
    When I switched from c++ to java, it seemed very obvious to me that this would happen, I just assumed that all experienced coders were using weak references. Out of curiousity, I asked on the forums how many people use weak references, the answer was "what is a weak reference?". Then I explained it's to prevent weak references, they just laughed at me: "dude, we have a garbage collector, we don't have to worry about memory leaks"

    1. Re:weak references by Shados · · Score: 1

      It may not even be just that. C# (and the .NET platform in general) is basically a compromise between garbage collecting systems like java, and low level C++ type stuff... C# is definately not memory leak proof (I mean hell, you CAN do pointer arithmetic and handle memory on your own if you want).

      Importantly, it has (especially in its windows incarnation) quite a few binding to non-.NET code. A lot of em. So you still need to call dispose on a lot of objects, or use the "using" block construct to make sure memory (and other ressources) get deallocated correctly in many, many cases... Its not quite as sandboxed as Java is (without external stuff).

      I've honestly never seen a semi-large C# program where developers didn't omit that aspect, deallocating these objects only if they read about that particular instance in a book or something, its sad. Even heavily audited financial/bank level packages and such made by reputable software development firms.

      And of course there's the other possibility which is exactly what you described, and that wouldn't supprised me either.

  58. Assembler by nurb432 · · Score: 1

    That is why you shouldn't use other companies 'tool kits'. You never know what garbage they have introduced, nor can you do anything about it.

    --
    ---- Booth was a patriot ----
  59. Misleading: mamory leak caused by their bug... by Anonymous Coward · · Score: 1, Informative
    If you've actually RTFA, you can see their memory leak wasn't caused by any internal memory leak in C#, or more correctly the .Net runtime, but by an implementation error they've made. Probably the same error would have been happend on Java or any other garabage collection enabled language.

    They've simply neglected to remove the event handlers for the "obstacle" objects, so they were still referenced and wouldn't be garbage collected:

    "Though we thought we had cleared all references to old entries in the list, because the objects were still registered as subscribers to an event, they were never getting deleted." So, maybe it's better to read and understand the article (which does seem like an advertisement to ANTS profiler), before just bashing an innocent programming language with no reason at all...
    1. Re:Misleading: mamory leak caused by their bug... by Anonymous Coward · · Score: 0

      However, if they were using a language that didn't encourage lazy programming, requiring that you do free memory after you're done using it, this wouldn't be an issue. Garbage collection only encourages laziness and creates sloppy code such as this by putting the idiotic notion into programmers' heads that they don't need to worry about such things, because the Magic Garbage Collector will fix it for you.

      This is why I strongly discourage using languages with this "feature".

  60. Why do we need unique tech? Breeds errors.... by Bearhouse · · Score: 1

    I love these DARPA challenges, and they seem to be working better for Uncle Sam than handing over gazillions to greedy, incompetent 'cost-plus' military sub-contractors. Good publicity, too...

    On the other hand, whilst I know it's 'the American way' to have a unique winner, perhaps the nexy step would be to encourage winning teams to create reusable, modular compotents / subsystems. Every winner is a unique expression of its creating team's creativity and technical competence. DARPA gets to keep the winning team's tech. Great. But will it blend - sorry, scale?

    If, each year, the teams could build upon ALL the previous teams developments, (kinda like FOSS model), then surely we'd all move together faster. No need to write lines of code for stereoscopic vision - use the module that worked best last year. Collision avoidance logic required? Download latest stable from Sourceforge, or secure DARPA equivalent.

    It's like the X prize - Rutan did a great job with SpaceShipOne, but nobody is pretending that it's really a technological stepping stone to civillian (orbital) space flight...

  61. Perpetual motion machine vendors by Dr.+Cody · · Score: 4, Funny

    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.

    1. Re:Perpetual motion machine vendors by Anonymous Coward · · Score: 0

      I was watching NUMB3RS last night and there was this water fountain experiment that they really didn't explain much - it seemed to me like there was a narrow return line (the fountain part) and a large reservoir (the pool). I think they were saying that if you put enough water in the reservoir that the pressure from the weight of the water would reach a point that it could drive the water back up the return line above water level enough that it would spill over back into the reservoir - perpetuating the cycle?
      It seems to make sense, they called it a hella fountain or helio, helous - something like that - anybody ever heard of that or tried it?

    2. Re:Perpetual motion machine vendors by Anonymous Coward · · Score: 0

      It's called Hero's Fountain. Suffice to say, the laws of thermodynamics are not impressed.

    3. Re:Perpetual motion machine vendors by SnowZero · · Score: 1

      Here's a page with an illustration that makes the operation of the fountain obvious. The other page explains the operation only in text, and pictures of old devices that were constructed to be deliberately misleading.

  62. 40-minute reset timer? by SquareOfS · · Score: 1
    From TFA:

    Because we didn't know why this problem kept appearing at 40 minutes, we decided to set a timer. After 40 minutes, we would stop the car and reboot the computer to restore the performance.
    So they knew that around 40 minutes, the performance would *gradually* degrade, and they fixed it with a timer that rebooted their system.

    People! Of course it's a memory issue -- not a leak, as everybody else has explained, but of course the issue is that your system got memory-poor. Of course. Nobody every checked the Windows task manager to say "Gosh, no more memory. Maybe that hurts us?" You don't need a profiler to figure out what this problem was; it probably helped to figure out where the problem was.

    The bigger question is, who sets a reset timer and considers their problem fixed, and, even if you don't have the timeline to find and fix the problem, who times the reset to the magic number of 40 minutes and not to the degrading performance?

    The truly amazing thing is that people bright enough to build the rest of this system could be so remarkably clueless about basic debugging.

  63. Re:As a C kernel programmer... by aproposofwhat · · Score: 1
    All part of the learning process, my good fellow :P

    Yes, there are leaks, sometimes because people make mistakes, sometimes because a poorly documented API is used, sometimes because a programmer is inexperienced or feeling lazy that day.

    That doesn't change the fact that a language is a tool, and using a difficult tool requires discipline, while using a more friendly tool makes for lax behaviour and hides the cause of errors.

    I'd rather use a sharp kife than a food processor, for example - it's easy to produce amorphous mush if you're lazy with the food processor, while a good knife chops only what you ask it to.

    --
    One swallow does not a fellatrix make
  64. Re:As a C kernel programmer... by mollymoo · · Score: 1

    No, but you don't often get C/C++ programmers going "well, it'll not be a memory leak, let's look elsewhere".

    --
    Chernobyl 'not a wildlife haven' - BBC News
  65. programmer error by icepick72 · · Score: 1
    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.


    ANTS doesn't fix Microsoft CLR problems. ANT fixes programmer problems. In other words, the logic was flawed. They didn't release their references properly and therefore the garbage collect didn't collect because the objects were still "in use". Princeton and DARPA and bad programming ... sounds like they should have called in the Comp. Sci. dept.

  66. FORTRAN by Per+Abrahamsen · · Score: 1

    Congratulation John Backus, you have just reinvented the first programming language.

    Dynamic memory became an official feature of Fortran 90, although it was a common extension much earlier than that.

    Older programs, also written in languages other than FORTRAN, tend to prefer static arrays over dynamically allocated arrays. As a result, older software tend to be ridden with fixed limits like max line length or max identifier length. In fact, the prime advantage (besides being free) of the GNU utilities over their Unix predecessors, was that the GNU utilities relied on dynamically allocated memory much more, and as a result got rid of most of the arbitrary limits. This was especially noticeable as the Unix utilities had static limits that made sense for applications running in the 64KiB memory space of the PDP-11.

  67. Hardly surprising. by Z00L00K · · Score: 1
    C# is known to the world as C-Hash. It seems to be the result of an ADA programmer smoking pot.

    Garbage collectors may be fine, but for some solutions they can be a problem.

    And of course - it's possible to get memory leaks just about everywhere regardless of programming language. It just depends on how "smart" the programmer is.

    --
    If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    1. Re:Hardly surprising. by gbjbaanb · · Score: 1

      Actually, its the result of a Delphi programmer being given so much money he thinks he's the best compiler designer the world has known, and a bunch of Microsofties being fooled by Sun's marketing machine into thinking Java was the best language ever.

      And its known as C-Octothorpe. :)

  68. C# makes no difference by wilsonthecat · · Score: 1

    It was written in Microsoft's C#, which isn't supposed to let you have memory leaks

    The CLR would have the memory leak, not C# which is just compiled into IL. Could've been VB.NET, Python, JScript, J#, F# etc. etc.

  69. Bad programming, bad design, bad environment by djinnn · · Score: 1

    This is clearly a programming mistake: they should have known they needed to unregister their event handlers.
    But more basically, this is bad design: if you're going to create so many objects you can crash the computer so fast, you should be using a pool of these objects in the first place (and reuse them). Why spend so much time allocating new objects and garbage collecting them?
    Finally, this is the wrong environment. If you're going to control a car driving in real time, wouldn't it make sense to use a real-time environment (language+OS) ?

    Gee, when i think those guys can find thousands of dollars for such a project and i can't find a job... ;-)

  70. brain food by icepick72 · · Score: 1
    Sitting in a McDonald's the night before the competition, we still didn't know why the computer kept dying a slow death.


    Their refined choice of restaurants and overspending may have lead to less funds available for the computer coding.

  71. In the C language ... by Skapare · · Score: 1

    ... you have to keep track of everything you allocate and be sure you clean it all up when you are done with it. That need does not go away with C# or other languages like Java. The danger with C is not that you might forget to free some object, but rather, that you do free some object and forget to remove a reference to it.

    --
    now we need to go OSS in diesel cars
    1. Re:In the C language ... by AlXtreme · · Score: 1

      The danger with C is not that you might forget to free some object, but rather, that you do free some object and forget to remove a reference to it.

      Euh, the danger with C is _both_ that you might forget to free an object _and_ that you are able to use free'ed references.

      The former leads to memory leaks, the latter to a lot more nastier problems. But both are dangers if you don't code defensively, it is only that memory leaks take longer to become a problem.
      --
      This sig is intentionally left blank
  72. nah by WindBourne · · Score: 1

    when I worked for Bell labys/Avaya, one of our switches was made with windows. We had to put in double the hardware for half the call capablities, and the damn thing crashed so often, that it quickly became the "blue screams of death". That thing sold at just 1.5 times our others switches in that matrix, and it was our only money loser.

    --
    I prefer the "u" in honour as it seems to be missing these days.
  73. This article is badly Slashdot-spinned. by Jugalator · · Score: 2, Informative

    Just read the CodeProject article to see why:
    - "so it wasn't a memory leak per se"
    - "It was the closest thing to a memory leak that you can have in a "managed" language. "
    - "Unfortunately, our system was seeing and cataloging every bit of tumbleweed and scrub that it could find along the side of the road."

    So they just goofed up.

    The objects didn't get deleted in time, because there were always ( literally ;-) )junk near them in the game, hence not getting garbage collected due to their object detection algorithm.

    Bad Slashdot. Bad Slashdot.

    --
    Beware: In C++, your friends can see your privates!
  74. parent should be informative by pikine · · Score: 1

    I can't believe more people modded the parent with interesting than informative. Unlike other posts that rants about bugs in C#, it is informative. TFA says:

    As we detect obstacles in each frame, we store the ones we detect. As the car moves, we call an update function on each of the obstacles that we know about, to update their position in relation to the car. Obviously, once we pass an obstacle, we don't need keep it in memory, so everything 10 feet behind the car got deleted. .... Though we thought we had cleared all references to old entries in the list, because the objects were still registered as subscribers to an event, they were never getting deleted.

    In essence, they really have two obstacles lists, one of which---the event subscriber list---is a mirror of the one being updated by stereo vision. Whoever wrote the code didn't decide correctly what to do about the mirror.

    --
    I once had a signature.
  75. Wow, how embarassing by TummyX · · Score: 3, Interesting
    If I was one of the team members, I wouldn't want my photo up there next to an article that documents my mediocre programming skills.

    Criticisms of the team aside, I would like to say that neither Java nor C# have made any steps to remedy problems like this with seem to be all too common with inexperienced developers. Both Java and C# need to support attaching to event handles with "weak" handlers. That is, the handler will not hold onto the object which defines the handler (and will automatically deregister itself sometime after the object has been collected). In many cases, there is a need for an object to listen and handle an event from another object, but only whilst the object that is listening is still referenced (with the exception of the reference held by the object firing the event).

    In C#, the (admittedly ugly) way to implement this is to use an anonymous method and a weak reference:

    // Need a weak reference to the current object (we want it collected)
    WeakReference weakRef = new WeakReference(this);
    // Need a local (not field) reference to object that raises the event
    SomeClass someObject = this.SomeObject;
     
    EventHandler eventHandler = null;
     
    eventHandler = delegate
    {
      ThisClass _this = (ThisClass)weakRef.Target;
     
      if (_this == null)
      {
          someObject.SomeEvent -= eventHandler;
          return;
      }
     
      _this.DoSomethingInResponseToEventBecauseWeAreStillAround();
    };
     
    someObject.SomeEvent += eventHandler;
    The "closure" that is created for the anonymous method does not hold a reference to "this" as it does not access any of "this"'s fields or methods unless it's through the weakreference.

    The code has a flaw where the event handler code (only a few bytes to hold the closure) will never deregistered be collected unless the event is fired sometime after the owner object has been collected. This can be fixed by using a NotifyingWeakReference (a weak reference that raises an event when it has been collected).

    1. Re:Wow, how embarassing by Tablizer · · Score: 1

      This is why I prefer using databases to track such. Databases are easier to monitor: you have query languages to study and monitor stuff from a bazillion angles. Plus info can "stay" even if the power is off. RAM and RAM-pointers are just too difficult to x-ray.

      Whether a database is too slow for this kind of project, I don't know. It may depend on the DB engine. But from a complexity-management angle, it seems a no-brainer.

  76. Depends how strictly you define your terms by jdickey · · Score: 1

    After all, to the average non-Redmondian, "Microsoft code" and "defects" are too often synonymous, no?

    1. Re:Depends how strictly you define your terms by SnowZero · · Score: 1

      If you happen to be in Redmond, just refer to them as "features" when you communicate to the locals.

  77. Misleading Headline by Ancil · · Score: 1

    As others have already pointed out, this isn't a C# problem. The objects weren't getting freed because there were still event handlers referencing them.

    Note to beginning C# programmers: A good way to avoid these types of problems is to use weak references when wiring up a large numbers of events.

    I have a little utility class called WeakEvent which just uses an anonymous delegate to check if the object's still alive. If so, it calls the event. If not, the delegate removes itself from the event chain. Problem solved.

    Your only other option is to remember to unsubscribe from every event when you're done with a listener object, so that it will be collected -- which pretty much defeats the purpose of using a managed language. Weak references: both .NET and Java provide them, but you have to make proper use of them.

  78. Re:As a C kernel programmer... by lordofwhee · · Score: 1

    Do you honestly not realize that EVERY programming language is compiled into ASM? The irony is unbelievable...

  79. Use a proper programming language by gilesjuk · · Score: 1

    If there's $2 million at stake and you're doing real time programming then use a proper programming language and OS.

    C/C++/ASM on a real time OS.

    Yes it's hard work, but get your algorithms and design right and you should be able to implement it in anything.

  80. Now we know by fast+turtle · · Score: 1
    why Windows Crashes


    Guess MS designed Windows to be like an elephant and never forget anything.

    --
    Mod me up/Mod me down: I wont frown as I've no crown
  81. Simply Bad Programming by Anonymous Coward · · Score: 0

    This is simply an example of bad programming.

    Objects are eprobably stored in a list of some sort, and no LRU (least recently used) checking is used to purge the list based on time.

    This is the kind of poor programming I would expect from J#/java/C# programms who are accustomed to 'let the software do it for me'.

    The same can happen in C/C++/Java/Basic/ADA/Perl.....

    Thats what you get for getting cut-rate programmers who cut their teeth on the language of the lowest common denominator.

    I will bet an embedded programmer would have found this in 10 seconds or less.

  82. Just a sales advertisement by sfmarco · · Score: 1

    This is only a sales pitch that tries to sell a software tool.

    I would have tested my software before the competition deadline. A heapdump would have shown their issue. You don't have to buy tools for that. Maybe they should buy a book.

    And yes, the same problem would have happened when they used java, or any other software language.

  83. Reboot every so often? (sign of failed process) by rhyre417 · · Score: 1
    Don't laugh, LAX airport (Los Angeles) was shut down in 2004 due to a communications system failure traced to bad software combined with bad procedures.

    At LAX, the Windows API call gettickcount() had an overflow problem,
    requiring a monthly reboot if the application wasn't coded around it.

    One time in 2004, the person responsible forgot, and the controllers
    at LAX couldn't talk. The problem isn't really Windows, it's a lack of
    good software processes.

    Here's what didn't happen effectively:


    http://it.slashdot.org/article.pl?sid=04/09/21/2120203 (LAX down due to comm system failure)

    http://it.slashdot.org/article.pl?sid=07/08/15/1829256 (LAX down due to NIC card failure on PC)

  84. in the URL by HeroreV · · Score: 4, Insightful

    Slashdot editors are even more pathetic than I thought they were. It's bad enough that they didn't skim through the article, but they apparently didn't even take a look at the URL. Look at this thing:
    http://www.codeproject.com/showcase/IfOnlyWedUsedANTSProfiler.asp
    "IfOnlyWedUsedANTSProfiler"? That didn't raise any flags?

    Of course, I'm trying to assume good faith and not just conclude that the editors knew this was an advertisement, but they sure are making that difficult.

    1. Re:in the URL by I+Like+Pudding · · Score: 1

      Slashdot editors are even more pathetic than I thought they were.

      Apparently you are not familiar with Zonk's oeuvre.
    2. Re:in the URL by blahplusplus · · Score: 1

      "Slashdot editors are even more pathetic than I thought they were."

      The truth is when running a website you'll have way too many submissions versus the amount of people submitting and reading your website. It would be great if Slashdot had "moderated" random editors, like they do with discussion... If anyones listening, mod my post up! :)

  85. More than one problem here :) by Anonymous Coward · · Score: 0

    From the TFA I assume some kind of callback handler still kept references to the object preventing automatic GC.

    This seems straight forward enough however this alone should not have caused the system to fail.

    Having the system lock up with the gas pedal depressed in my estimation is a very troubling design flaw that in itself even without the GC bug should have disqualified this group from participating in the grand challenge.

    People using high level codes for automated vechicles or automated sentry guns without necessary modeling to assure acceptable failure modes deserve what they get.

  86. Real time OS and language by Matthieu+Araman · · Score: 1

    Reading the article makes me perplex.
    I wonder why the programmers don't use a real time os with a real time language.(this doesn't seem to be the case reading the article)
    I agree it may seems harder to program at firstt but a good conception can avoid these stupid case when the car just bump into something because the computer hasn't been able to calculate in time...
    Having seen a real car taking 10s to answer to the stop button because it was buggy in certain conditions and the manufacturer had just released the car too early to respond to market pressure makes me afraid of what we will see in the future when car becomes more and more automated...

  87. Re:As a C kernel programmer... by gbjbaanb · · Score: 1

    which is a good thing - a program that crashes during development is easy to fix. A program that slowly gets worse and worse and is only noticed when shipped is difficult to fix. I know which I prefer, from bitter experience! And to top it all, this was a 10k loc program, hardly anything major - imagine you had one of these leaks in a million loc app, built out of a dozen components.

  88. Would this even make it as a story... by fuali · · Score: 2, Insightful

    ...on slash dot if it was written in perl on the linux platform. This is just an oppurtunity for someone to read part of a story, make a snappy title that bashes Microsoft based on the misunderstanding of the technology in an article.

    This is not a c# memory leak, it was a memory leak written in c#. The developers used a commerical tool to find there problem, a trail version even. So how about a title "Commercial Code Profiler Saves the Day For DARPA team"?

    Oh because then it would never be a slash dot article, ugh.

    Developers making a mistake != c# bug

    The IDisposable interface is there for a reason.

  89. It runs windows... by Anonymous Coward · · Score: 0

    How has no one mentioned that they're running the car on windows? I think that was their first mistake...

  90. Bad programming on the team's part by YAN3D · · Score: 1

    It wasn't a memory leak caused by the C# garbage collector, it's the fault of the programming team not removing their event listeners properly.

  91. Bad Bad article title by simonech · · Score: 3, Insightful

    I usually like /. articles, even the ones against MS, but I cannot just skip over this one:
    if the moderator read the article he would have noticed that the article was an advertisement for the profiler product, not just a review of it (it was written directly by Red Gate).
    Second, the article itself says that they found that the error was in how they coded the application, because they left some reference so the garbage collector didn't trow away the objects.
    This is a really bad article and bad information.

    1. Re:Bad Bad article title by nil0lab · · Score: 1

      Sorry dude. I worded it kind of over the top in the hopes it would attract attention and be accepted. It worked.

  92. Don't Slashvertise. Ever. by spun · · Score: 4, Insightful

    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.

    --
    - None can love freedom heartily, but good men; the rest love not freedom, but license. -- John Milton
  93. I wish I could mod this down. How bizarre... by 5n3ak3rp1mp · · Score: 1

    1) As anti-Microsoft as I am, this was not C#'s fault. They had a hidden reference to the objects that were not getting garbage-collected. The way this article is posed, however, is blatantly FUD. Shame!

    2) The article itself is a not-so-veiled advertisement for a profiler.

  94. This is advertisement by miguel · · Score: 1

    Some other folks at 4 or 5 already have commented on the fact that this is not a C# bug or a .NET bug, but a programmer mistakes, so I will not elaborate.

    But the article linked to was authored by "RedGate Software" for the Code Project, so it is basically an advertisement for their product. Their product did help the team fix their bug, so maybe that is good.

    But the bug was discovered and fixed in 2005:

    http://pave.princeton.edu/main/archives/114

    So what happened is that probably Red Gate wanted to score some PR points over at the Code Project and they digged up a story from their existing customers, decided to sponsor the guys in exchange for a few quotes that they could put on the article to promote their product.

    It would probably not gone too far, except the guy that submitted the story thought he had found the smoking gun against C#.

    Miguel.

    1. Re:This is advertisement by Etrigoth · · Score: 1

      Haha! Good find :)

      I knew the article was bogus, but the fact that it happened 2 years ago, really puts this to bed O_o

      --
      When we remember we are all mad, the mysteries disappear and life stands explained.
  95. Re:As a C kernel programmer... by xforce · · Score: 1

    Wrong... in at least two ways. Not every programming language is compiled. Usually compiled programming language generates binary code ( aka machine language ) not ASM code.

  96. Re:Holly Crap! Manslaughter 101 by Anonymous Coward · · Score: 0

    They designed a machine that they KNEW would run out of control with potentially deadly results. If it had run over someone, these guys would surely be arrested for manslaughter.

    They were not designing a production machine for the road. Their machine was a product of research into autonomous vehicles, designed to work in a government laboratory. In this case, the laboratory was the Mojave Desert.

    When a robot falls over or overheats and catches fire in a research lab there's no call to jump up and shout about how the creators made a dangerously flawed machine. When a chemist leaves a reaction heating too long and the result is a toxic chemical instead of the intended medicine, there's no reason to get up in arms. It happens all the time in laboratories. The Princeton team forgot to add a reagent to a beaker, and their experiment didn't work. If this kind of thing didn't happen with autonomous vehicles there would be no need for DARPA to mount a competition to design them.

  97. bs checker by freeasinrealale · · Score: 1

    potential_bs_str = "We had vacations coming up a few weeks after the race, so we left the cars in Vegas and returned, two weeks later, to investigate the problem."

    if(bs_test(potential_bs_str)){
        prints("Nobody takes vacation before problem solved in Real World");
    } else {
        Remain_skeptical_anyhow();
    };

    --
    A man spends the first half of his life accumulating stuff, the second trying to get rid of it all.
    1. Re:bs checker by /dev/trash · · Score: 1

      You obviously don't work with me then.

  98. interpreted languages for vehicle navigation? by NynexNinja · · Score: 1

    Why would anyone write a vehicle navigation system in an interpreted language anyway? Microsoft gives out these languages hoping people will use it, yet none of their code actually uses it. C# reminds me of GWBasic from the 80's or Visual Basic from the 90's.

  99. C# delete statement by MobyDisk · · Score: 1

    Managed languages should have a a delete statement that acts like an assert. It tells the GC that this object should be deleted now, and the GC looks at the object and throws an exception if there are any references to the object. It doesn't have to actually delete at the point, but it is a way for the programmer to ask the CLR "Are there any other places that reference this object? If so, I want to know about them so I can fix them"

    Instead, there are $5,000 tools that try their best to guess what objects are supposed to be deleted, and come up with tons of false positives and things.

    On a related note to this, it sounds like their particular problem was with C# events holding objects. There are various people who have made weak-reference events that prevent this problem in the first place. It is rare that you want an object to be held alive just because there is an event on it.

  100. Re:Friends do not let Friends use Windows and Driv by Anonymous Coward · · Score: 0

    If you are into snuff films you should check this out.

  101. Poor misled idiots by uassholes · · Score: 0, Troll

    I've always said that if you use Microsucks shitware, you get what you deserve.

  102. Re:As a C kernel programmer... by stephentyrone · · Score: 1

    I code everything in assembly. It's much easier to debug than C, C++, C#, Java, or damn near any other language you can name. The only drawbacks to assembly is that it's insidiously non-portable, and you need to keep in mind all kinds of issues that a good compiler can deal with for you -- it takes me about 3 times longer to write a complex assembly function than it takes me to write the C analogue. So why code in assembly? What I get in return is completely transparent debugging -- I can step through my code per instruction in a debugger, not have any mysteries about execution order, what the optimizer is doing, etc. The resulting code is typically between 30% and 200% faster than compiled C code. That's a huge win for system library functions or core computational routines that will be used in tight loops. I can't speak for the grandparent, but I don't "avoid using useful tools merely because those tools aren't 100% perfect". I avoid using tools which are the wrong tool for the job. The question I have is: what job is Java/C# the right tool for? I can't think of one. If performance matters, really really matters (I mean, lives and dies by cycle count), then they're too slow. If performance isn't so important, there are more powerful languages in which it's easier to write clean code. These guys at Princeton probably could have written everything in OCaml / Python / Lisp and had no troubles at all. As for getting left behind as progress marches on... I'm a young guy. I'm the only young guy I know who writes production quality assembly. Interestingly, I also get paid more than my other friends who are software engineers, and I have no worries at all about my job being shipped out to Elbonia. I look at the output of bleeding edge compilers, and work with compiler guys to try to improve their backend codegen. I know they told you in school that compilers were smart, and you should just lay out your algorithm properly and trust the compiler. They lied. My job's not going anywhere.

  103. Advertise Your Worst Practices by WED+Fan · · Score: 1

    So, if I understand the "article", the rookie students got caught with their pants down on bad coding practices and should have used any of tools, free or not, to profile their app and find the problems before going to production.

    Can you imagine the folks at Red Gate trying to convince them:

    "Hey, we'd like you to expose how big an idiot farm your programmer team is, but at the same time, we'd like to post it as an avertspamicle. We'll even put your pictures on the "article" and post it to a well read tech board, and even get it submitted to a even more well read tech site. Everyone in the WORLD will know about your short-comings. Sounds good to you?"

    Lessons learned, but I hope every employer will keep their picture handy, in case they get a resume from anyone on the team.

    --
    Politics is the art of looking for trouble, finding it everywhere, diagnosing it incorrectly and applying the wrong fix.
  104. Team Cornell's AI by vectra14 · · Score: 2, Informative

    I'm from team Cornell, #26. We finished the race (although slowly due to what looks like a buggy throttle controller). C# was used exclusively in our system for the strategic planner. It was also used quite a bit for the behavior/operational systems.

    I'm very much a C++ programmer, and with a strong focus on micros to add to that, so yeah, I was a bit... skeptical.

    At one point in development we did have a "memory leak" issue but it was entirely our fault (while obviously there are no "new"/"delete"'s around, if you don't dereference things then essentially you get a nice "memory leak" with all of the associated symptoms).

    I think that C# really sped up our development time, and, in the end, our car finished. I'm sure that there are other fully valid languages/IDEs/etc, but we happened to be most proficient in MSVS; we tested the crap out of C#'s compiler's performance on our machine for our specific application; we used it and that part of the system performed admirably. C# also let us write numerous support utilities quickly.

    Microsoft may have many faults but I'm pretty sure that C# / the Visual Studio IDE environment as a whole aren't it.

    Princeton seemed to have a number of issues outside of "slowing down" during runs. They completely scrapped their first two qualification runs, ran maybe once, and then left.

    P.S. No, i'm not paid by microsoft or such. Aside from the usual departmental benefits like free copies of MSVS and winXP, we didn't get any kind of sponsorship from them.

  105. The right answer to memory management by Animats · · Score: 2, Informative

    There's actually an accepted safe way to do memory management - reference counts and weak references. That's what both Perl and Python have settled on, and it's worth noting that programmers in those languages seldom have serious memory management problems. In C and C++, one has to obsess on memory management issues, and even in Java and C#, which are garbage collected, it takes more attention than it should.

    Reference counts have the advantage of repeatability - deletion will occur at predictable times. This allows the use of destructors. You can safely use destructors to manage other assets, like windows, open files, network connections, and such.

    Destructors in systems with garbage collection make for an unhappy marriage. Calling a destructor or finalizer from the garbage collector is essentially equivalent to calling it at some random time from another thread. So race conditions are possible. Check out Microsoft's "managed C++" for an attempt to get all the cases for this right. It's not pretty.

    The classic complaint about reference counts is "what about cycles"? There's a simple answer - cycles, that is, loops of strong pointers, are errors. This isn't a severe restriction; it just requires some data structure design. With trees, for example, links towards the leaves are strong pointers, and links towards the root are weak. (I've revised Python's BeautifulSoup HTML parser to work that way; "down" and "forward" links are strong, while "up" and "backwards" links are weak. It took about 20 lines of code and eliminated annoying problems in programs dealing with HTML trees.)

    If you really need a symmetrical circular list, which might happen in, say, a window library with many links between widgets, there's a simple solution. Have all the objects owned by some collection, then use weak pointers between them. When the collection is dropped, all the bits and pieces go away, in a well defined order.

    In Python, you can turn off garbage collection while leaving reference counting active, then list any orphaned cycles at program end for debugging purposes. This is a practical way to program without leaks or garbage collection. It's generally easy to find cycles, because cycles are created by data structure design, not by bugs. So if a program has cycles, it will probably have them every time, and thus they can be found early in debugging. With better language support for debugging, cycles could be caught at the moment of creation, which would make it easy to eliminate them.

    Now if we could get this into a hard-compiled language, we'd have the problem solved. Repeated attempts to bolt reference counting onto C++ via templates have resulted in fragile systems. The fundamental problem is that C++ still requires access to raw pointers to get anything done, and this puts a hole in the protection provided by the reference counting system. It takes language support to make this work right.

    1. Re:The right answer to memory management by Anonymous Coward · · Score: 0

      You should look the open source BlackBox CP compiler... their garbage collector works roughly that way (or better i think)

    2. Re:The right answer to memory management by Animats · · Score: 1

      You should look the open source BlackBox CP compiler... their garbage collector works roughly that way (or better i think)

      Sadly, no. Component Pascal does not have deterministic destructors. So you can't use destructors to release resources at the appropriate time, and you have all the problems mentioned above with destructors being called at a random time. See section 10.4: "The FINALIZE procedure can be implemented for any pointer type. The method is called at some unspecified time after an object of that type (or a base type of it) has become unreachable via other pointers (not globally anchored anymore) and before the object is deallocated."

  106. What side effects for weak references? by tepples · · Score: 1

    the only thing the runtime could do to protect the idiot developer (myself included) is automagically make all event references WEAK references, but that has plenty of undesirable side-effects too Like what? If a library's developers were to specify that the library creates weak references for all event-listener relationships, what would that break?
    1. Re:What side effects for weak references? by __aasmho4525 · · Score: 1

      who knows how many thousands of pieces of software were written that DEPEND upon this particular reference to ensure that the object doesn't get garbage collected?

      alredy written software would have to most likely change, that's all i was trying to imply...

      cheers.

      Peter

    2. Re:What side effects for weak references? by Anonymous Coward · · Score: 0

      It's fairly common to have the event handler be the *only* reference for a large number of objects in a system. Doing what you say would require that the programmer add lines of code just to have strong references floating around.

      There's also the fact that weak references are valid until garbage collection. As a consequence, if you dropped your strong reference, and the event fired, the object would respond to the event depending on whether the gc has fired. Explicitly unregistering seems preferable from a code-what-you-mean perspective. Besides, if you have lines of code explicitly un-referencing an object just for that purpose, why not un-register it? Again, the code would have clearer semantics.

  107. Slashdot not a news source? Agree! by KWTm · · Score: 4, Interesting

    Slashdot is a blog not a news source. I wish more people would realize that.
    Agree. It's time to get this out in the open.

    People complain that Slashdot sucks: the headlines are sensationalistic, the editors get commissions based on the number of dupes they post, and articles about 6-month-old events get posted as "news".

    So why do I even bother visiting Slashdot? The answer is two things: the community of posters, and Slashcode moderation.

    The value of Slashdot is in its community. You and I, dear Slashdotters. Our collective mind will pick through the various articles, point out their flaws, expose sensationalist FUD for what it is (and, surprisingly, will do this equally for anti-Linux and anti-MS FUD), debate various trends, and provide a signficantly international (though heavily USA-centric) perspective.

    This value is enhanced by Slashdot's moderating system, so that information and insight can bubble to the top among the mass of inane posts. Metamoderation limits the amount of crack that the moderators can be on.

    So, Slashdot editors, take note! *WE* are the reason we are here. *YOU* are not. Many of us don't even bother to read the articles any more, preferring to soak up the collective wisdom of techies from varying age groups and fields. If you piss us off, and the collective community of Slashdot deteriorates, then there's no reason for me (or others) to keep coming back.

    Think about it.
    --
    404555974007725459910684486621289147856453481154 in hex is "You sank my Battleship?"
    [GPG key in journal]
    1. Re:Slashdot not a news source? Agree! by Anonymous Coward · · Score: 0

      mod this puppy back up... it is not off topic to its parent post

    2. Re:Slashdot not a news source? Agree! by cornface · · Score: 1

      So, Slashdot editors, take note! *WE* are the reason we are here. *YOU* are not. Many of us don't even bother to read the articles any more, preferring to soak up the collective wisdom of techies from varying age groups and fields. If you piss us off, and the collective community of Slashdot deteriorates, then there's no reason for me (or others) to keep coming back.

      Think about it. They probably would take note if it actually mattered. If you read any of the "inside slashdot" type posts, it is always mentioned that the people that read the comments are a tiny fraction of slashdot's user base, and the people that bother to post are an even tinier fraction of that.

      So basically you have a nice point, but it is not in any way based in reality. Only a deluded sense of self-importance made even sillier by being based on the internet.

    3. Re:Slashdot not a news source? Agree! by fuliginous · · Score: 1

      Interesting that he is right within the subgroup. In that the people who enter the discussion are the people that matter because without them we wouldn't be in the discussion.

      I'll add to that a suspicion, which is if we members of the discussion and (meta)moderators weren't here to pick up and demolish some of these stories for being sensationalist etc the whole thing would fail. The commentary that can be sometimes scanned to see a distilled nugget of the real story, the discussion that eventually turns up as a later story refuting the earlier crap and so on.

      So all in all I think it's probably true.

  108. Is it documented? by tepples · · Score: 1

    As much as I wanted it to be a bug in the C# runtime, it's just another PEBKAC issue. I treat persistent PEBKAC issues as possible defects in TFM. The API documentation for event listeners should specify what kind of reference (ordinary or weak) the library uses, as well as the ramifications of this choice. Does it?
    1. Re:Is it documented? by bar-agent · · Score: 1

      The API documentation for event listeners should specify what kind of reference (ordinary or weak) the library uses, as well as the ramifications of this choice.

      The operation for adding an event subscriber is "event += subscriber." That syntax pretty obviously makes a reference to the subscriber in the event, and that is explicitly documented on the website.

      But no, the API documentation should not be discussing the ramifications of this. The developer needs to know the ramifications. That is basic knowledge that should be discussed once in an "About References" section, and not in every class that keeps references (which is all of them). The developers in the article did know the ramifications, in fact, they just didn't remember that the objects they wanted to free were also event subscribers, thus the event was keeping them alive.

      That, I think, is a flaw in the API design. An event is basically presented as a callback method. Callback methods can't own things, only objects should own things. One would expect the subscriber to keep a reference to events that it is interested in tracking, not the other way around.

      The Cocoa NSNotificationCenter design is better, because, though it works similarly to C# events on the inside, it is presented such that the developer can use the common-sense model above.

      The most intuitive model is probably to declare a method that the event notifier magically know about it and calls when the event happens.

      --
      i'd hit it so hard, if you pulled me out you'd be the king of britain [bash.org]
    2. Re:Is it documented? by borgboy · · Score: 1

      I don't remember any any API doc in any garbage collected language that specified that a given reference was a strong (aka NORMAL) reference (as the general case). Weak references are specified because they are rather out of the norm, for most general-purpose programs. Yes, I know, all of you are geniuses and you use them all the time. Us normal idiots don't. Last time I had to use them I was foolishly rolling my own cache
      In any case, no, this isn't a persistent PEBKAC problem among competent practitioners. References are assumed to be strong unless documented otherwise.

      --
      meh.
    3. Re:Is it documented? by tepples · · Score: 1

      I don't remember any any API doc in any garbage collected language that specified that a given reference was a strong (aka NORMAL) reference (as the general case). Then the documentation for the API should still make it clear that the API holds on to a reference, in those cases where holding on to a reference might trip up users of the API.
  109. Re:As a C kernel programmer... by Tim+Browse · · Score: 1

    Usually compiled programming language generates binary code ( aka machine language ) not ASM code.

    Not so much. That's an artifact of the interface. Most compilers will output assembly language, and the tool chain will convert the assembly files into binary machine language afterwards (by calling some form of assembler). You might just as well say that most compilers generate executable images, because most compilers will chain to the linker unless you specify otherwise.

  110. Actually it's probably our fault by Crazy+Taco · · Score: 2, Insightful

    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.

    I suspect it is the fault of slashdot user base as much as the editors. I bet a lot of users were in the firehose, saw the sensationalist title, etc, and rated it highly. The editor comes in, sees it has a sensationalist title and is now colored read, meaning users really think it is great, and posts it. So yes, the editor may not have read the article, but I'm sure the user base didn't either, at least not until after it got posted.

    --
    Beware of bugs in the above code; I have only proved it correct, not tried it.
  111. There are other ways to leak in .NET by Chabil+Ha' · · Score: 1

    When you reference and make calls to unmanaged Win32 DLLs, you can run into leaks real quick. Because those libraries run on Win32 C++ code, it is still up to the developer to reclaim that memory within their .NET managed code.

    For example, if you use the GDI+ library, you have to explicitly call the Dispose() method to free up the memory it is using, otherwise your C# app will continue on its merry way with that memory still allocated.

    --
    We're all hypocrites. We all have hidden parts, it's the contrast between them that make us more a hypocrite than others
  112. Using a garbage collected language for this is rea by melted · · Score: 1

    Using a garbage collected language for this is really stupid. To add to the choir, this is not memory leak, so C# is not really at fault here. There's another issue with GC languages, however. Every now and then runtime will suspend all application threads and run garbage collector. Your program is _stopped_ during GC, which means the car doesn't "see" anything through its cameras, doesn't control throttle, brakes or steering wheel. In a desktop or a web app, you won't notice a few milliseconds of interruption. Choice of C# for this particular application, however, strikes me as odd. You need a language where you can control everything and which doesn't get interrupted unpredictably - C, C++, Ada - there are a number of different languages people use for realtime computing.

  113. GCC generates asm source by tepples · · Score: 1

    Usually compiled programming language generates binary code ( aka machine language ) not ASM code. I can't speak for other compilers, but GCC generates assembly language source code and pipes it into the platform's assembler. This allows it to work with architectures before Binutils supports them.
  114. Use Microsoft, get Screwed! by Anonymous Coward · · Score: 0

    The only thing I would expect that is left out is a reference to the fact that if the system had been validated by WGA (Windows Genuine Advantage) that the memory leak would not have existed. Every time one of my students pays for Microsoft software, it doesn't work. Only the cracked coppies work!

    LMAO!! These morons were probably using "legit" coppies from Microsoft, thus the WGA invalidation, and thus the failure of their vehicle.

    Even ONE decent debugging tool would have told them what was going on, but Microsoft sues anyone who tries to publish a real debugger that can show what's really going on in DOT-NET.

    I think the license agreement even prohibits benchmarking or reporting on the performance of ANY code written in DOT-NET. If that's the case, then these poor schlubs have violated the EULA by mentioning that the code stopped responding, and their entire university is liable for piracy.

    I predict that within 24 hours, Microsoft will:
    1. revoke all academic licenses at their school (without telling them)
    2. sue everyone who attends their school
    3. call the ATF / BSA / SS / FBI HRT tactical teams to go after select team members. Watch for that school to look like Waco, TX did on 4-19-1993.

    Andy Out!

  115. You underrate portability by tepples · · Score: 1

    I code everything in assembly. It's much easier to debug than C, C++, C#, Java, or damn near any other language you can name. The only drawbacks to assembly is that it's insidiously non-portable Which poses somewhat of a problem if your business model involves selling copies of the same program for both PCs and non-PC platforms such as handheld devices.

    The question I have is: what job is Java/C# the right tool for? Sandboxing and portability. Most popular PC operating systems don't provide rich sandboxing primitives for native code or don't expose them to the user. Java technology, on the other hand, has a security manager, allowing custom interactive elements in web pages to run in a safe environment without requiring the user to install a web browser extension. Applets also work on Windows PCs, Macintosh computers (especially important before the Macintel transition), and handheld devices.
  116. Could there code have been so pathetic by mrmeval · · Score: 1

    that they bombed it and got money from "Ant" for "fixing" it later?

    That's weapons development at it's finest. Just ask the Sgt York team.

    --
    I'd go on a Vegan diet but the delivery time from Vega is too long. --brownkitty
  117. LOL!!! I'm adding this to my sig. by 7String · · Score: 1

    It's not a memory leak. It's an object life-span issue.

    --

    It isn't a memory leak. It's an object life-span issue.
  118. Not surprising. by clayne · · Score: 0

    "We had vacations coming up a few weeks after the race, so we left the cars in Vegas and returned, two weeks later, to investigate the problem. One of our team members downloaded the 14-day trial of ANTS Profiler and we ran it on our car's guidance code. We profiled the memory usage and saw the obstacle list blowing up."

    Except a C programmer would have done this before even starting up the car.

    "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."

    Which is why newer fisher price languages with automatic garbage collecting are bad in the long run - they don't expose the programmer to enough manual intervention such that they take it for granted.

    Humans are incredibly prone to complacency.

  119. Typical ./ crap, trying to bash Microsoft by niin · · Score: 1

    And, of course, very few will actually read the article. This wasn't a 'bug in C#'. Not even close. It's a bug in the programmer. They left a reference hanging around to objects they no longer needed, thus the object never was garbage collected. "Though we thought we had cleared all references to old entries in the list, because the objects were still registered as subscribers to an event, they were never getting deleted. ... We added one line of code to remove the event subscription and, over the next three days, we successfully ran the car for 300 miles through the Mojave desert. "

  120. Your sig by Schraegstrichpunkt · · Score: 1

    :(){ :|:& };:

    Is that supposed to use up all the available process IDs?

  121. Aspect-oriented? by tepples · · Score: 1

    The most intuitive model is probably to declare a method that the event notifier magically know about it and calls when the event happens. How would that work, without using the poorly understood COMEFROM statement that is method name regex oriented programming?
  122. Mod Parent Up by mad.frog · · Score: 1

    Misleading headline. They had a stupid bug in their code that caused the leak. (Easy to make, but stupid nonetheless)

    Question: does C#/CLR have weak refs as a feature? Seems like event listeners ought to be registered as weak refs by default to prevent this sort of problem...

    1. Re:Mod Parent Up by BalanceOfJudgement · · Score: 1

      Question: does C#/CLR have weak refs as a feature? Seems like event listeners ought to be registered as weak refs by default to prevent this sort of problem...


      Yes it does, but they're almost never used. Event multicast delegates are always registered as strong references. This is why their software was bogging down:

      For someone who'd written 10,000 lines of C# code, it seems they never picked up on the idea that merely removing an object from a list doesn't delete all references to it. I wasn't a paragraph into the article and I knew what their problem was, and it was their fault, not a C# memory leak.
      --

      We are the fire that lights our world.. and we are the fire that consumes it.
    2. Re:Mod Parent Up by BalanceOfJudgement · · Score: 2, Informative

      I thought I'd add:

      The next version of the .NET Framework, 3.0/3.5 uses Weak References by default for almost all event handlers you care about. .NET 3.5 runs on the 2.0 CLR though, so it's simply finally using the weak references provided by the CLR.

      --

      We are the fire that lights our world.. and we are the fire that consumes it.
    3. Re:Mod Parent Up by petermgreen · · Score: 1

      making your event listeners weak references would kinda screw things up when an objects only job was to listen to events.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    4. Re:Mod Parent Up by PhireN · · Score: 1

      For someone who'd written 10,000 lines of C# code, it seems they never picked up on the idea that merely removing an object from a list doesn't delete all references to it.
      That was one of the things I thought about many times when I was doing c# coding back in high school, and I wrote nowhere near 10,000 lines of code, maybe 2000. I think I tried hard to have only a single reference to each object, inside a static array, belonging to that class, or a parent class.
    5. Re:Mod Parent Up by BalanceOfJudgement · · Score: 1

      That was one of the things I thought about many times when I was doing c# coding back in high school, and I wrote nowhere near 10,000 lines of code, maybe 2000. I think I tried hard to have only a single reference to each object, inside a static array, belonging to that class, or a parent class.


      Same here. I spend alot of mental effort keeping track of every object I use when doing .NET coding. No, I don't have to worry about freeing things like strings, but for anything I actually attach to, I immediately make sure to write the code to detach from it.

      It seems obvious to me. Yet, I'm aware there are many coders who never learn this.

      Thing is, I came from C/C++. I prefer .NET by far, because it allows me to more intuitively design my objects, but I've taken an attention to detail from the lower languages that I think someone simply jumping in is going to miss.
      --

      We are the fire that lights our world.. and we are the fire that consumes it.
    6. Re:Mod Parent Up by try_anything · · Score: 1

      Seems like event listeners ought to be registered as weak refs by default to prevent this sort of problem...
      It's easy to imagine situations in which weak refs would be useful, but in practice, I've written a couple thousand lines of GUI code over the last several months, and I can't recall a single instance where I would I have preferred a weak reference over a strong one. In the vast majority of cases I want the listener to have the same lifetime as the object it listeners to. In all of the remaining cases, I want to dispose the listener at some definite time, and at that time I am able to unregister the listener. I know that isn't much experience, but I think it's enough to claim that weak refs should not be the default: if they were the default, I would have to do a lot of extra typing to ask for strong refs, and I would probably have a few subtle bugs where I accepted the default. Strong refs are the more common case, and they fail in much safer and more deterministic manner. (If you leak memory because of strong refs, you always leak memory, and you always leak the same amount for a given workload workload. If your listeners randomly disappear because you accidentally used safe refs, you may have a hard time reproducing it in testing.)

      On the other hand, I can imagine situations where weak references would greatly simplify things. Those situations basically boil down to the following: the listener's role is to operate on a third object, whose lifetime is unpredictable, in response to listenee events. The listener weakly references the third object, and the third object strongly references the listener. When the third object becomes eligible for garbage collection, so does the listener. Of course, when the listenee is disposed, the listener continues to live because it is referenced by the third object, which may not be desired.

  123. Erm, they're STUDENTS... by mad.frog · · Score: 1

    ...cut 'em some slack.

    If these were seasoned pros, then yeah, they would deserve the jeers... but "student" implies "still learning the craft". This is the sort of mistake they are expected to make once in a while.

    1. Re:Erm, they're STUDENTS... by WeirdJohn · · Score: 1

      And they're being taught to develop reliable systems on a platform where rebooting is a regular maintenance task and a standard bug fix technique. What the students do reflects immediately upon their instructors, or so I believed when I taught in a University.

  124. Re:Don't Slashvertise. Ever. by zufar · · Score: 1
    Here is a interesting quote from the Princton racing team's page http://pave.princeton.edu/main/ which leaves no doubts on wether it's news or marketing

    New Sponsor September 26th, 2007 PAVE is excited to announce that our friends from across the pond, Redgate Software are our latest sponsor. Redgate makes a variety of software tools for use with SQL and .NET, including the ANTS Profiler, which our team used back in 2005 to successfully fix the memory leak that prevented Prospect Eleven from traveling more than 9.5 miles in the Grand Challenge.
  125. Not a C# fault by Anonymous Coward · · Score: 0

    Don't blame C# for memory leaks. Blame the mediocre software testing that was applied (or not applied) to this project.

    1. Re:Not a C# fault by Anonymous Coward · · Score: 1, Funny

      But I thought C# was supposed to solve all of my memory management problems for me!

    2. Re:Not a C# fault by Zoolander · · Score: 1

      I was going to write a funny reply to this, but I can't remember what it was now.

      --
      Meep.
  126. Re:As a C kernel programmer... by goofy183 · · Score: 1

    Not really, the people that don't clean up object references in memory managed languages are the same people that wouldn't manage resources correctly in a non memory managed language. For good developers the memory management removes a lot of work that really isn't needed. There still needs to be care placed in to ensuring you clean up references though. I would put some blame on folks that teach/market these languages like as if you don't need to worry about memory at all. Of course you need to worry about memory, just in a slightly different and usually less intensive way.

  127. Bad summary. but obvious FREE solution by Brett+Buck · · Score: 4, Insightful

    Hey, here's a wacky idea that's just crazy enough to work - DON"T USE DYNAMIC MEMORY ALLOCATION! Why in holy hell would someone construct what amount to an embedded real-time system using dynamic memory. Define fixed memory allocations for everything. Run tests. If the memory is insufficient, the program crashes. Then you can see where the program crashes and why. Then you can fix it.

          Just because you *can* do something doesn't mean you should.

              Brett

    1. Re:Bad summary. but obvious FREE solution by nil0lab · · Score: 1

      Yup. Bad summary. Not mine. Even if they did add "nil0lab writes..." at the top.

  128. Oh please by Anonymous Coward · · Score: 0

    At this point, everyone expects an anti-Microsoft bias from Slashdot, but this crosses the line into blatant misinformation. Pure and simple FUD. The submitter either doesn't understand how memory management works in a managed language or just doesn't care.

  129. Garbage Collectors Cannot... by Bellum+Aeternus · · Score: 1

    Garbage collectors cannot release "unused" memory if they cannot tell the memory is unused. Poor coding skills and an assumption that a magical garbage collector will save you is just not smart. I can easily code something that eats memory like no tomorrow and never releases one bit of it in Java, C#, etc... managed languages only work if you code with them correctly. Blame the developer, not the language.

    --
    - I voted for Nintendo and against Bush
  130. ANTS? by Eddy+Luten · · Score: 1

    If only we used ANTS profiler? Is this really news or a commercial block? Give me a break.

    And why did they use C# for this project?

    1. Re:ANTS? by Eddy+Luten · · Score: 1

      PS, did you guys notice that the article was submitted by Red Gate Software, the makers of ANTS profiler? It wasn't even released by the guys from Princeton.

  131. Most home PCs do not run a modern OS by tepples · · Score: 1

    as just one silly example, it would suck if you wouldn't be able to explicitly close a file, because you can't delete it before it's closed Just to nitpick, I've never seen this problem on any modern operating system I've used.

    Unfortunately, the supermajority of home PCs do not run a modern operating system. They run Windows.[1] Unlike UNIX file systems, which store inodes separately from file names, Windows stores them together. Unlike a UNIX system, which removes the file from the directory and schedules the inode for deletion once all processes have closed it, Windows does not allow a file to be deleted if any process has it open.

    [1] Some people claim that the NT kernel is beautiful and the Windows userland screws it up.

  132. If you don't like it... by Colin+Smith · · Score: 1

    Then why not fuck off somewhere else?

    --
    Deleted
  133. Re:As a C kernel programmer... by cyber-vandal · · Score: 1

    In which case why use a high level language at all - surely coding everything in Assembler would be the way to go.

  134. what do they expect from a marketing company by Locutus · · Score: 1

    Microsoft's history is full of software engineering flaws and anybody who continues to use their products in a critical tool is playing a fools game. Microsoft's #1 goal is not technical excellence and never has been. And I'm not saying that Microsoft is the only one to do badly at software engineering, it is just that they are so good at doing it repeatedly.

    BTW, remember when LAX was shutdown for hours and there were a few in-flight near misses because the LAX Comm system went down? That was because they used Windows 98 to run that COMMs system and it had a flaw which caused it to crash after something like 38 days. IIRC, this flaw was only found something like 3 years after Win98 shipped and goes to show you how unreliable Microsoft operating systems are. Nobody could keep it running for over 38 days for over 3 years. And then, some bozo decided to base a rewrite of a UNIX based air traffic COMM system on Microsoft Windows....

    IMO, the Princeton guys were idiots for picking Microsoft "technology" for this project.

    LoB

    --
    "Anyone who stands out in the middle of a road looks like roadkill to me." --Linus
  135. Slashdot *does* have editors. When I submitted... by nil0lab · · Score: 4, Interesting

    Slashdot has editors. I know this, because the stuff below "nil0lab writes..." is heavily editted from what I actually submitted! In fact, I started my actual submission with something like "in a shameless plug for some code analysis product..."

  136. It's not. I didn't. I was editted! by nil0lab · · Score: 2, Interesting

    I sent this story to slashdot, and I'm not a marketer nor do I have any
    relationship with the product. In fact, I started my submission (which
    was editted, see other comment above) with something like "in a blatant
    plug for some kind of profiling product..."

  137. Re:Using a garbage collected language for this is by petermgreen · · Score: 1

    If a delay of a few milliseconds is a serious concern you really need an OS you can tightly control too.

    --
    note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
  138. Another reason by Trogre · · Score: 1

    To pronounce C# in the non-musical:

    See-hash

    --
    "Nine times out of ten, starting a fire is not the best way to solve the problem." - my wife
    1. Re:Another reason by jtwine · · Score: 1

      To pronounce C# in the non-musical: See-hash
      Or my personal favorite - if you identify the # symbol as an octothorpe: C-octothorpe or coctothorpe
      --
      -=- James.
  139. Author of this article is a moron. by Axe · · Score: 1

    That is not a C# memory leak: "Though we thought we had cleared all references to old entries in the list, because the objects were still registered as subscribers to an event, they were never getting deleted."
    That was just some bad programming and debugging.

    --
    <^>_<(ô ô)>_<^>
  140. Re:Don't Slashvertise. Ever. by Anonymous Coward · · Score: 0

    Besides that, what good is it to advertise a C# profiler to slashdotters. Slashdotters would never use c# to begin with (since they consider it devil-spawn).

  141. Correction by Anonymous Coward · · Score: 0

    He was also a devote Utahnian.

    He was also a Utard.

    There. I fixed that for you.

  142. This couldn't be true by running+mate · · Score: 1

    I have been developing and running large scale C# applications over 4 years now. I had seen some performance inconsistencies, but never a complete stall. When working with automatic garbage collected framework, it is important to understand that such inconsistencies are part of the equation. If one wrote a hard realtime app on top of the framework, how could it be MSs mistake? I'm convinced that this could only be a programming mistake or a high leve decision making error where they decided to use C# for not what it is good for.

  143. Re:Don't Slashvertise. Ever. by MMC+Monster · · Score: 1

    Not only that, but the entire thing ends up being indexed by google, so the next time someone is looking for your service, they end up with a /. discussion by experts mentioning how bad the product is and how good and cheap the alternatives are.

    --
    Help! I'm a slashdot refugee.
  144. Jeez, ya think? by bXTr · · Score: 1
    From the first sentence of TFA:

    This is a showcase review for our sponsors at The Code Project. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.
    --
    It's a very dark ride.
  145. Bad title by Anonymous Coward · · Score: 0

    More appropriate title would be "Memory leak in program written in C#".

  146. The "Doh" article of the day by kilodelta · · Score: 1

    I cannot for any amount of time believe that any of the teams used a Microsoft product and expected it to be perfect. Open source was the way to go on this one and they blew it.

  147. Bad software by lnxpilot · · Score: 1

    I would never drive a car or fly and airplane that has Microsoft software in it, so what were these guys thinking?

  148. The real interesting stuff by johnqh · · Score: 1

    Anyone read the article? They were using stereo vision to detect obstacles. That is pretty cool. However, I have doubts that they wrote this part themselves because nobody with reasonable mind would use C# for image processing. It is possible a DirectShow filter doing the processing, and the C# code uses managed DS. The biggest problem is they have the obstacle objects listening to an event? Why? What kind of event would they be listening to? Anyone care to guess?

  149. Part of the game. by pontifier · · Score: 1

    Just in case anyone is confused, this is about the Grand Challenge in '05, not the most recent Urban Challenge this year('07).

    I was on the Utah DARPA Urban Challenge team, and Princeton was supposed to test right after us every day. Neither of us made it to the finals, and I question the logic that they used in eliminating teams so early. We only had 1 opportunity to try test tracks A and B, and each time we fixed the minor bugs that stopped us. If we had had a second try on either of these tracks, I think we would have had a shot at the finals, but they cut us just as we thought we had all the bugs worked out, and before we could show them what we could do.

    I think most teams have stories about what went wrong, and what they should have done, that they didn't do. I know that we did. I know even the winners have goals for what they want to do better next time.

    --
    -John Fenley
  150. Pretty basic problem by lena_10326 · · Score: 1

    The developers can't debug worth shit. I've run into similar problems in production code (such as graphics contexts in java or cyclical references) and it usually doesn't take that long to figure it out.

    Pretty shoddy debugging... IMO. Too bad CS departments don't put more emphasis on debugging.

    --
    Camping on quad since 1996.
  151. Defamatory title, embarrassing skillz by Drubber · · Score: 1

    First off, the article intro should be updated, unless /. would like to further capitalize on the false (and defamatory) title. There was no "C# Memory Leak" in this code just as there is no "C memory leak" in other similar, poorly-tested programs.

    I was sadly unsurprised when I read TF Advertisement and found that, in fact, C# and the runtime had been working perfectly WRT this problem. The delegate reference (anonymous function pointer) was holding a reference to the target object, the source of the event, just as expected.

    Second, I am shocked that this bug was not used as a "learning moment" for the people working on this project. This type of problem will continue to vex these people as they move from academia into the real world of building systems and applications. That is, until they learn how to debug problems. A significant portion of a developer's time is tracking down and fixing this sort of thing. It's also something that would have been found rather quickly with basic debugging skills.

    For future reference, here's a little tutorial.

    1. Start the system and let it run.
    2. Watch memory consumption. You may even use a basic tool such as the Task Manager on Windows (although I'm sure, what was it?...Red Gate, is a fine product).
    3. If memory consumption grows unabated, you have a leak somewhere. Time to start instrumenting your code.
    4. Look at all of your allocations (grep new *.cs), start with those key objects that there are likely to be a lot of (e.g., ones that get added to lists).
    5. Add two static variables to any such classes: allocatedCount and deletedCount.
    6. Restart the program.

    You can trace or dump these variables and start watching trends (liveCount = allocatedCount - deletedCount). If it had been done in this program, the problem would have been spotted instantly. You're lucky that it was a leak--usually easy to find--not the kind of "Heisenbug" that can bite developers in other languages, like C, in which an uninitialized variable can cause a problem to only show up sometimes; for example, only when run for 10 hours and only when run outside of a debugger.

    When working on problems like this, the kind that can take hours or days to find and fix, the finding part is what takes all of the time. The diagnosing and fixing part is usually pretty quick and painless. The delegate reference that was the cause of this problem would have been spotted pretty quickly, I would venture.

  152. GetProcesses() steals memory by BenJeremy · · Score: 1

    The result of GetProcesses() won't free up the memory once it leaves scope, nor does manually going in and freeing the individual Process data. I even tried freeing the individual members of the class, elements that should have been marshaled in.

    I had a problem using this in a loop, ended up using a different technique to get the information I needed (I was scanning for a process starting up and shutting down). My app consumed over 1GB in an hour, before I figured out the culprit, I tried forcing garbage collection, finally ended up doing a post-mortem on the heap and seeing that bits of the Process information data was still sitting out there, somehow orphaned, then attempted to remedy that, but C# apparently prevented me from freeing those orphaned elements. My "fix" was to use instances of the Process performance counter (all I needed was the names of the currently running processes), and I've tested it over a period of days with no memory consumption (beyond the initial 20MB or so the app needs to run)

    The lesson here is: Don't use GetProcesses() in a loop.

  153. Re:As a C kernel programmer... by todhsalstodhsals · · Score: 0

    Serves them right for using C#. You'd think in today's world everybody would write their code in C or C++ and use algorithms that don't dynamically allocate memory, then use flexelint, then use a memory tester as the final step. No, these half wits use M$. They've got to prove they can't do things right and are so stupid they'd put their fate in M$'s greedy hands. I'd like to see more articles like this one! Little ivy league schoolers getting burned for being incredibly stupid. Didn't Bush and Kerry come from Princeton... No wonder these kids are using C#!

  154. Proper term by heinzkunz · · Score: 1

    Memory leaks only happen in compiled languages. In managed languages, it is called "packratting".

  155. Problem was the time needed to call event handlers by I'm+Don+Giovanni · · Score: 1

    As many have already said, this wasn't a "C# memory leak", but an app bug, and solutions have already been offered (use weak references, or just remember to deregister event listener at the same time as the app deletes the event listener object from the collection).

    But I think people have been missing what the real problem was.
    From what I'm reading in TFA, the problem wasn't really a "running out of memory" issue, it was that more and more event listeners were being registered, so every time an event occurred it took more and more time for the event to fire. They say that after 40 minutes or so, the system began to get slower and slower and slower, and would eventually grind to a halt. I think the problem wasn't lack of memory, but that eventually gazillions of event listeners were registered so it took forever to call them all.

    --
    -- "I never gave these stories much credence." - HAL 9000
  156. Using c# on mission critical software by goffster · · Score: 1

    Surely you were asking for it. C# is a propreitary language, written by *one* company. The only reason I can possibly think of for such an inane choice is that Microsoft might be a sponsor.

    1. Re:Using c# on mission critical software by triso · · Score: 1

      Surely you were asking for it.

      C# is a propreitary language, written by *one* company.

      The only reason I can possibly think of for such an inane choice is that
      Microsoft might be a sponsor. What is even worse is using Windows for your development and deployment OS. That is as dumb as bending over in a prison shower to get the bar of soap you dropped.
  157. thanks by Anonymous Coward · · Score: 0

    They also had a hot chick soldering, the iron slipped or something an part of the circuit board exploded ala Star Trek. Good episode.

  158. VB by egork · · Score: 1

    Let me try to come up with a statistical explanation. More often than not people programming in VB are concentrating on shallow tasks. (e.g. only MS Office applications) Their "good enough" and "I feel lucky" attitude is not counterbalanced by concerns that come with experience of solving tricky tasks in heterogeneous systems. So they can not foresee what is not "good enough" from their limited experience.

    I saw people running SQL queries for each value from a list, instead of creating a table and doing all in one table scan. This all worked until the database got more workload and could not come back with results in time anymore, making the application unusable. Did they have to work with mass-data server application, where one learns to always try to be efficient with production code, they would have seen this ugliness and invested a bit more time.

  159. Re:It's not. I didn't. I was editted! by Raenex · · Score: 1

    Ok, then the next question is why did you submit a product plug as a story? And why would the editors accept a story labeled as such?

  160. Library, not language by CustomDesigned · · Score: 1

    It is the library, in particular event notification, that "caused" the problem. The language was fine. The same thing happens in Java when beginning programmers forget to unregister objects from event sources (or anything else requiring registration). I use the term "data cancer" to distinguish this type of bug from actual "memory leaks", which are in fact impossible with a working GC.

  161. Re:Exactly why I don't program in garbage collecte by FKnight · · Score: 1

    Why? Because you also are too stupid to dereference your objects so a GC can clean them out?

  162. Automatic GC kung fu by caywen · · Score: 1

    Automatic GC is a lot like a pair of nunchucks. If you walk down the street with them whirling it around, it looks pretty badass and no doubt you can hurt someone as intended. After your first street thug goes down, you definitely feel like badass. Just don't confuse yourself with Bruce Lee. You'll likely wind up giving yourself a black eye with 1 bad twirl. Deterministic GC is a lot like one of those kung fu fold-fans. Really hard to do damage, but one of those old, bearded guys will tear you a new asshole with it. Kung Fu baby.

    1. Re:Automatic GC kung fu by Anonymous Coward · · Score: 0

      huh?