Skip to main content
13 events
when toggle format what by license comment
Oct 30, 2013 at 21:02 comment added MarkJ +1 Here's an MSDN link from 2003 explaining why a deliberate decision was made to move away from the COM reference-counting model, so that the garbage collector could cope with circular references and also for performance reasons. "If a group of objects contain references to each other, but none of these object are referenced directly or indirectly from stack or shared variables, then garbage collection will automatically reclaim the memory."
May 10, 2013 at 10:48 history edited Stephen C CC BY-SA 3.0
added 1 characters in body
Jul 12, 2012 at 2:36 comment added supercat @dan04: From what I understand, it's more than syntactic sugar, since C++/CLI defines am IDisposable.Dispose method to include not only the user-specified dispose code, but also disposal calls for IDisposable fields that the class owns.
Nov 8, 2011 at 1:59 comment added dan04 @Larry: I agree. C++/CLI does use ~ as syntactic sugar for IDisposable.Dispose(), and it's much more convenient than the C# syntax.
Nov 7, 2011 at 22:59 comment added Larry OBrien @Peter Taylor -- right. But I feel that C#'s non-deterministic destructor is worth very little, since you cannot rely on it to manage any kind of constrained resource. So, in my opinion, it might have been better to use the ~ syntax to be syntactic sugar for IDisposable.Dispose()
Nov 7, 2011 at 22:33 comment added Peter Taylor C# does have a destructor syntax, it just doesn't have guarantees on when it will be called. It's a common pattern to make classes which implement IDisposable also implement a destructor as a fallback in case the user forgets the using clause.
Nov 7, 2011 at 21:13 comment added JoelFan @Larry Obrien... once the stack variable goes out of scope the destructor is called.
Nov 7, 2011 at 20:58 comment added BlueRaja - Danny Pflughoeft +1 this is the only correct answer so far - it's because Java intentionally doesn't have (non-primitive) stack-based objects.
Nov 7, 2011 at 20:55 comment added Larry OBrien (And, as far as it goes, I have no idea how they can GC "through" reference types whose lifetime is determined by the stack.)
Nov 7, 2011 at 20:52 comment added JoelFan No... just put the relevant code in the destructor
Nov 7, 2011 at 20:48 comment added Larry OBrien C++/CLI has a very different set of design decisions and constraints. Some of those decisions mean that you can demand more thought about memory allocation and performance implications from the programmers: the whole "give em enough rope to hang themselves" trade-off. And I imagine that the C++/CLI compiler is considerably more complex than that of C# (especially in its early generations).
Nov 7, 2011 at 18:48 comment added JoelFan What about what C++ / CLI (.NET) has done, where the objects on the managed heap also have a stack-based "handle", which provides RIAA?
Nov 7, 2011 at 18:43 history answered Larry OBrien CC BY-SA 3.0