Does WinRT have Garbage Collection?
Asked Answered
R

1

22

Does WinRT have Garbage Collection?

Or does it do reference counting as does COM?

Rodenhouse answered 15/9, 2011 at 0:52 Comment(2)
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)Guzel
"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."Overdone
R
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.

Rappee answered 15/9, 2011 at 1:16 Comment(10)
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.Bunko
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.Glossotomy
@Glossotomy 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.Bunko
@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?Glossotomy
@Glossotomy /FAs dumps the assembly listing with source in comments, see msdn.microsoft.com/en-us/library/367y26c6(v=vs.80).aspx; /Zw is new in VC11 and enables those language extensionsBunko
@dalle: "Metro C++" is not a layer above WinRT, it's a WinRT language projection. And of all projections (others being .NET and JS), it's the closest one "to the metal". It hides AddRef/Release/QueryInterface from you, and it also wraps HSTRING and HRESULT, but it doesn't try to significantly alter semantics. So, yes, it is refcounted. If you don't take my word for it, have a look at the disassembly.Bunko
@Glossotomy Also, yes, the syntax is not strictly needed to consume WinRT from C++ - you can indeed use smart pointers, and in fact you can find some at "C:\Program Files (x86)\Windows Kits\8.0\Include\winrt\wrl" in Developer Preview. However, you forget that there's more than refcounting here to deal with - there's also QueryInterface (both calling and implementing it), strings, and exceptions. These all are much more concise as language extensions, and once you have those, it makes sense to move smart pointers there as well, just for the sake of more concise syntax.Bunko
@Pavel Minaev: I take your word for it. It surely sounds promising, but I don't see why they couldn't use standard C++ syntax. Why invent another language? But this is getting really OT.Glossotomy
let us continue this discussion in chatBunko
@dalle: I believe Microsoft decided to use C++/CX as a language projection, because compiler support for a projection based on Standard C++ was still lacking. In the meantime, compilers have implemented new C++ features, and looking at Modern, it seems that it's possible to implement a WinRT projection purely as a Standard C++ library.Overdone

© 2022 - 2024 — McMap. All rights reserved.