[RESOLVED] Why .Net not use smart pointers instead of GC?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [RESOLVED] Why .Net not use smart pointers instead of GC?

  1. #1
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673

    [RESOLVED] Why .Net not use smart pointers instead of GC?

    Hi, my question is why didn't .Net use smart pointers instead of Garbage Collector to do memory management?

    In that way, the memory will reclaimed automatically when there is no variable reference the object, and memory usage will be always compact, and there is no need for a garbage collector program running.

    Thanks for answering my query!
    Share on Google+

  2. #2
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815

    Re: Why .Net not use smart pointers instead of GC?

    Quote Originally Posted by CBasicNet
    Hi, my question is why didn't .Net use smart pointers instead of Garbage Collector to do memory management?
    Although I'm not in the VC++ team, I can answer that for you:

    The reason is that smart pointers (or more generally speaking: object reference counting), as used in VB 6, fail to handle the case of circular object references - they will normally lead to orphaned resources. That's where garbage collection comes in (not only with regard to .NET, but in a very general sense: It's the reason why GC had to be invented after all, and is also used by other languages / environments, like Smalltalk for example).
    Share on Google+

  3. #3
    Join Date
    May 2006
    Posts
    22

    Re: Why .Net not use smart pointers instead of GC?

    Hi: I'm Jonathan Caves and I'm a developer on Visual C++ compiler team.

    The reason that the .NET runtime uses a garbage collector is that it is desgined as multi-language runtime: as well as C++ it supports VB, C#, Eiffel, Cobol, and other languages. So you can't really use a C++ specific technology like smart-pointers (which require templates) for a language neutral technology like the .NET runtime. Having said that I am more that certain that the .NET runtime itself, which is mostly written in C++, makes use of smart pointers internally.
    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center