diff --git a/Frameworks/CoreGraphics/CGImage.mm b/Frameworks/CoreGraphics/CGImage.mm index 7dd8a8705a..fd19f05fec 100644 --- a/Frameworks/CoreGraphics/CGImage.mm +++ b/Frameworks/CoreGraphics/CGImage.mm @@ -39,15 +39,13 @@ static const wchar_t* TAG = L"CGImage"; -// TODO #1124: remove old code -#pragma region OLD_CODE +// This is used by XamlCompositor to flush the DisplayTexture cache. +// TODO GH#2098 look at where we're using the image cache and what we can do to avoid it. static std::vector _imageDestructionListeners; COREGRAPHICS_EXPORT void CGImageAddDestructionListener(CGImageDestructionListener listener) { _imageDestructionListeners.push_back(listener); } -#pragma endregion OLD_CODE - #pragma region CGImageImplementation struct __CGImageImpl { @@ -225,6 +223,12 @@ inline WICPixelFormatGUID PixelFormat() const { _impl.renderingIntent = intent; return *this; } + + ~__CGImage() { + for (auto listener: _imageDestructionListeners) { + listener(this); + } + } }; #pragma endregion CGImageImplementation