Memory Management in Windows Runtime

As I saw in Windows 8 for .NET developers, .NET deals with native platform objects. And these objects support counter pointers. It was clear to me that there are managed objects that are in the managed heap and unmanaged that we had to release in the finalization and deletion methods. At the moment, it is not clear to me how to work with memory management in Windows Runtime. Can you give me advice when I need to worry about managed / unmanaged resources? And how does memory management work in a Windows Runtime environment to prevent my apps from leaking?

UPD:

I mean the .NET Metro Profile

+4
source share
1 answer

The main WinRT interface is based on COM. Each WinRT interface comes from IUnknown, its AddRef and Release methods implement memory management based on reference counting.

However, this is very well hidden when you are programming a WinRT application, then you are using a language projector. For .NET and Javascript applications, language projection is built into the CLR and Chakra engine, respectively. Which completely hide implementation details, WinRT interfaces are mapped to native language constructs. Including skillfully creating the illusion that COM supports generics and implementation inheritance. A somewhat reasonable guess is that the CLR projection uses the support for COM interoperability already built into the CLR, but this cannot be easily rebuilt. To be precise, finalizers are likely to make an IUnknown :: Release () call.

Now it’s very difficult to get decent information about low-level details, Microsoft bloggers and SO posters don’t say, the source code is not available, and issues affecting the topic are closed, for example this one .

As you can tell from Chen's comment on this, you should not be interested in this. If you're worried, think about C ++ / CX programming. What is good to hide the glue. Or native C ++ with the WRL library, but it is not. Both runtimes in which memory management is explicit. Microsoft has invested a lot of resources to reuse C ++ programming.

+4
source

All Articles