Windows 8 Runtime: Break circular dependencies

Underneath there is some code snippet from one of the SDK samples. Be aware of circular dependencies, get familiar with weak pointers!

auto view = ref new View();
view->Initialize(m_window, m_applicationView);
view->Run();

// Must delete the view explicitly in order to break a circular dependency
// between View and CoreWindow. View holds on to a CoreWindow reference most
// typically for window activation, while CoreWindow refers back to View when
// event handlers are hooked up. Without breaking this circular dependency,
// neither View nor CoreWindow object gets to clean up. It's also important
// to note that a 'delete' call on a ref class instance simply means calling
// into a class destructor in order to explicitly break a cycle. It doesn't
// actually deallocate any memory.
delete view;
Advertisements

About Jan Tschada

Software engineer from Germany
This entry was posted in Common. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s