22

Does WinRT have Garbage Collection?

Or does it do reference counting as does COM?

2
  • 1
    Yes WinRT has some sort of Garbage Collection, the more interesting questions is what sort is it? (reference counting is a valid type of Garbage Collection if it is well hidden from the programmer like in VB6, rather then ATL) Commented Sep 15, 2011 at 8:37
  • "Does WinRT have Garbage Collection?" - Yes. "Or does it do reference counting as does COM?" - That, too, is garbage collection. It seems that everybody thinks about garbage collection the wrong way: "Garbage collection is simulating a computer with an infinite amount of memory [by] reclaiming memory that the program wouldn't notice went missing." Commented Jul 5, 2016 at 8:01

1 Answer 1

24

I found this article, which cites Microsoft's Martyn Lovell:

"WinRT objects are reference counted like COM for memory management, with weak references to avoid circularity."

Apparently this was mentioned at his talk on WinRT internals at the BUILD convention.

10
  • 8
    As a side note, while it's kinda obvious, it's still worth clarifying that a .NET app using WinRT will still have GC running that will handle .NET objects. Similarly, JS has GC for its own objects. It's only WinRT objects that are refcounted. Commented Sep 15, 2011 at 4:16
  • At the bottom of .NET there is Win32 and COM which are also refcounted. Stating that .NET is refcounted because of this would be as true as stating that Metro C++/CLI(-ish) applications is refcounted.
    – dalle
    Commented Sep 15, 2011 at 8:12
  • 4
    @dalle There's no COM at the bottom of .NET, in a sense that .NET objects are not COM objects. However, WinRT objects are COM objects - they implement IUnknown. And, yes, in Metro C++ apps using the new /Zw compiler syntax, instances of ref class types are refcounted, using AddRef/Release. So are strings, though they have their own refcounting functions. Compile with /FAs and see for yourself. Commented Sep 15, 2011 at 8:23
  • 1
    @Pavel Minaev: .NET objects are not COM objects, you are correct in that. But .NET use Win32 and COM objects for all system related calls as Windows doesn't have a system .NET API. WinRT is probably refcounted, but the layers above it, such as MetroC++, probably aren't. If they were refcounted the extended MetroC++ syntax wouldn't be needed at all, as standard C++ handles refcounted objects with ease. EDIT: Do you have documentation links for /Zw and /FAs?
    – dalle
    Commented Sep 15, 2011 at 8:31
  • 1
    let us continue this discussion in chat Commented Sep 15, 2011 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.