From my understanding C++/CX doesn't use garbage collection, it use a reference counted approach instead.
The problem with reference counting is that it cannot dispose of cycles. Cycles are usually solved using weak references, such as weak_ptr in standard C++.
But I cannot find a way in C++/CX to explicitly specify a weak reference. From that I would assume that this is handled by C++/CX itself. I am wondering how C++/CX would solve this.
For instance, look at the following code:
ref class Foo
{
public:
Bar^ bar;
};
ref class Bar
{
public:
Foo^ foo;
};
ref class App
{
public:
virtual void OnLaunched(LaunchActivatedEventArgs^ args)
{
Foo^ foo = ref new Foo();
Bar^ bar = ref new Bar();
foo.bar = bar;
bar.foo = foo;
}
};
How does C++/CX detect this cycle?
How does C++/CX solve this cycle?
How does C++/CX decide which one of these objects should be the "root object" and which one should be the "weak reference"?