Jason Zander - Discussing the architecture and secrets of .NET and the CLR
- Posted: Nov 23, 2004 at 10:22 AM
- 42,562 Views
- 7 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
This is the classic ref counting vs tracing debate. Brian Harry's explanation of the trade offs is still the best explanation of this. Highly recommended reading.
Good idea, tracking down bit hoses from dangling pointers and double deletes is far surperior <g>
Seriously, no memory allocation system is going to be a silver bullet. I do believe that automatic memory handling in general has been a huge win, and I wouldn't change the decisions we made on the product.
btw, the Dispose pattern and using keyword were created as a result of the dicussion Brian's aticle generated.
If instead you think of Dispose() being the equivalent of the destructor and do all your cleanup there, you call Dispose() on the object instead of using the delete statement, you have almost the same situation you have in C++ - the only difference being that the actual memory isn't freed immediately and I believe there are very few situations were that matters much.
Personally I find the using statement in C# to be rather ugly. I am rather impressed by the way the new C++/CLI implements the Dispose pattern to make your code look like trational C++ with automatic/stack allocation. Jason says in the video that the compiler generates a lot of code to do that but I think that's irrelevant becuase if you wanted the lifetime of the object to be controlled you would have to write that code yourself anyway.
More interesting is their conclusions, which can be found here: http://www.sellsbrothers.com/writing/refcount_rotor.doc.
Seems like performance is the major problem refcounting introduces.
Lookout is indeed an amazing app!!!
Do you have plans to integrate the functionality of it in the next version of Outlook? That would be fantastic.
Personally I find the using statement in C# to be rather ugly. I am rather impressed by the way the new C++/CLI implements the Dispose pattern to make your code look like trational C++ with automatic/stack allocation. Jason says in the video that the compiler generates a lot of code to do that but I think that's irrelevant becuase if you wanted the lifetime of the object to be controlled you would have to write that code yourself anyway.
I couldn't disagree more. Under C++ most destructors were just calling other destructors anyway, and all that's gone with automatic memory management. Thus classes that hold scarce resources and actually need to be disposed ought to be, and in my experience are, somewhat rare. I don't mind having syntax to remind me that this class holds a scarce resource.
IU hope the C++/CLI team is smart enough to only provide deterministic finalization of ojects that implement IDisposable, otherwise theyu are generating a look of code for no benefit.
If you have a class that needs to free resources, implement IDispose and free those resources there, calling other object's Dispose() methods if necessary. In C++/CLI, the delete statement calls Dispose on managed objects if they implement IDispose. Additionally it calls it when managed objects allocated automatically go out of scope.
Forget about finalizers - they always were and even more so now are just a last resort. They can free resources for objects were lazy client code forgot to call Dispose() by calling Dispose() themselves, or you could add code to your debug build so that if the finalizer gets called for a class that implements IDispose, it logs an error. Then you can trace what would be memory leaks in the equivalent native C++ code.
Remove this comment
Remove this thread
close