AttributedString leak (Windows)

I noticed that my application's memory working set was getting out of control when I move the mouse a lot.

Pinpointed it to some newly added AttributedString::draw I put in a paint method.


Steps to reproduce:

  • Get Juce tip
  • Go to JuceDemo::MainWindow.cpp::paintListBoxItem a.draw line (line 179)
  • Wrap it in a 100 iterations for-loop.
  • Compile, start the demo and rapidly swap menu items (keyboard or mouse) (I just swapped between the Welcome! and the Shortcut Keys items with the up/down arrow keys).
  • Watch the working set soar into oblivion.


(Note: Adding the loop just amplifies the effect - if you're patient enough you can spot it without the loop).

Reproduced in both Debug and Release modes

Using Windows 8.1 Update 1, Visual Studio 2013 Update 2

Does not reproduce in OS X (10.9 / Xcode 6)

Maybe a leak somewhere inside the DirectWrite code.. I don't have a win8 machine handy, but could you check whether any leak detection messages get emitted when the app quits?

There's no leak detection breakpoint upon app termination. I tried my best to debug it and try to find the leak. but to no avail. I think it's in juce_win32_DirectWriteTypeLayout.cpp::createLayout (330). Using my application for more than an hour without restarting it will now crash it :(

Btw, why not get a Windows 8 VM?

Bit of a mystery, this one.. It does seem to be a Win8 bug, and I've reproduced in on win8 myself, but on Win7 everything seems fine.

I've checked all the DirectWrite smart-pointer usage, and AFAICT everything is done correctly, there are no leaks of DirectWrite objects in my code. I can only guess that something within the Win8 implementation of DirectWrite is misbehaving or keeping a reference hanging around internally.

Really not sure what to do about this - it could take days of trial-and-error debugging to determine which of the DirectWrite classes are at fault, and there isn't necessarily even a workaround..

I tried searching for complaints about Windows 8 specific DirectWrite memory issues, couldn't find anything, not to say that there aren't any, though.

I have no idea how to continue from here, it seems like my only option is not to use DirectWrite at all. This probably goes to all Windows 8 JUCE users - check your application for leaks, especially in cases where you refresh a component that uses AttributedStrings frequently.