Apr
17
2009
Tools // WPF

Memory leak with WPF resources

I am working for a couple of months now with WPF and MVVM on an a business application using .NET Framework 3.5 SP1. Lately I faced a memory leak. Not the easy kind of memory leak with events handlers which keeps objects and its element tree alive, as explained here.

No it was something else ! I searched in our code for quite some time without finding anything.

My internet research brought me to a blog post from Ramon de Klein, “Memory leak with WPF resources (in rare cases)” which stated :

When does the problem occur?
The problem occurs in the following situation:

  1. A style is defined in the application’s ResourceDictionary.
  2. The style uses a control template that uses media effects (i.e. DropShadowEffect).
  3. The media effect should be referenced using a StaticResource.

We were matching the two first points and I tried the proposed fix:

You can force the effect to be frozen by specifying “PresentationOptions:Freeze=True”, but this is not common behavior.

The workaround is simple… Just add the Freeze attribute to all the effects that you don’t plan to modify at runtime.

But that didn’t made it.

I decided then to move the style definition from the application ResourceDictionary to the MainWindowView ResourceDictionary, which was for sure a better place for it. This to avoid the first point.

This worked! And we do not have this memory leak anymore. But as always when you fix one, some other popped up! But that’s another story.

How did I came to find the blog post from Ramon de Klein ?

With a perfect timing I got an offer from Red Gate to test their latest tool still in Early Access Program: ANTS Memory Profiler 5

You might watch a two parts video here (part1) and here (part2) and read about it here. You can even download a version from their forum, check it out.

First I used ANTS Memory Profiler 5 Timeline to see that the memory wasn’t released at certain points in which it should. The red line shows the Bytes in all Heaps and should go down after each vertical line (gray, blue and red)

Same result with Process Explorer, Memory usage going up without going down.

So we got on the screen the memory leak. Next step was to identify it.

Using Memory Profiler Class List, I browsed to the class that I new should be released, and proved it wasn’t: Live Instances is 3 and Instance Diff is +2. So at that time I knew that this class was maintained by something in memory.

Watching the Memory Profiler Instance list, I could identity the different instances still in Memory and one wasn’t new, so a good candidate to look at:

Finally switching to the Memory Profiler Object Retention Graph, I could navigate up the graph to see that DropShadowEffect was maintaining a reference:

Up to my application RessourceDictionnary, as exaplained in point 1 from Ramon de Klein blog post, as you can see.

All those information gave me the opportunity to find the blog post from Ramon and led me to the solution.

This is the result of the fix I implemented, as you can see I have now only one Live Instance of the ProductViewModel class and an Instance Diff of –1. This shows that the object wasn’t retained in memory and cleaned correctly.

 

ANTS Memory Profiler 5 and Ramon de KleinMemory leak with WPF resources (in rare cases)” blog post was of great help to fix this memory leak. Thanks!

Thanks flies also to Stephen Chambers for the support with my questions on ANTS Memory Profiler 5.

Finally I would like to warmly THANKS Laurent Bugnion for his kind chats that helped a lot, as always!

Apr
17
2009

Five Ways To Build Team Trust & Framework for Feedback

I am for quite some time now working on the Agile subject and tonight I read two very interesting posts that I wanted to share and keep track of.

The first one was posted by Mike Bria on InfoQ and is called Five Ways To Build Team Trust, in which advises are given to help trust form within teams.

    1. Address Issues Directly.
    2. Share Relevant Information.
    3. Follow Through on Commitments or Give Early Notice When You Can't.
    4. Say No When You Mean No.
    5. Show What You Know and What You Don't Know.

The second post, “How I learned about Feedback” is from Ola Ellnestam, Agile Coach, Systems developer, Agile Practitioner, and is an excellent report on experiences applying a “feedback framework” learned from a workshop held by Esther Derby and Diana Larsen.

Framework for feedback

Esther Derby and Diana Larsen introduced me to a ‘Framework For Giving Feedback’. It looks like this.

  • Create an opening
  • Describe the behavior or results
  • State the impact
  • Make a request

I find this framework very easy to use and powerful. So, when I’m about to give feedback in tough or new situations I try to run through the scenario in my head, creating an imaginary outcome of the conversation. This has helped me several times. Lets look at the ‘meeting issue’ again.

Enjoy

Apr
17
2009
WPF

Attending the "WPF FOR LOB" TRAINING TOUR in London

Next month I will attend with my colleague Robert the “WPF FOR LOB” training Tour in London (5/15 -5/16). Our flights and hotel rooms are already booked. We fly from Zurich to London Heathrow on Thursday 14 Mai arriving at 20:15 in London and I fly back to Mulhouse on Saturday evening.

We will be at the conference hotel Radisson Edwardian Heathrow Hotel, where the training take place.

Jaime Rodriquez and Karl Shifflett have been organizing a “WPF FOR LOB” to provide 2 days of free WPF training for developers.

Overview
This two day training is designed to teach developers how to create Line of Business (LOB) applications using Windows Presentation Foundation (WPF). 

  • Day One is an introduction to the WPF graphics subsystem, the tools used to build WPF applications, and the core UI services: styling, data binding, templating, layout and input-
  • The second day begins with interop (Windows Forms and Win32)  and then quickly dives into LOB topics, including building applications using the Model-View-ViewModel pattern, creating unit testable applications,  implementing data validation, and error handling. 

After completion, attendees will have a solid understanding of WPF, its advantages over other Microsoft UI platforms, and how to use the M-V-VM pattern to create great WPF LOB applications.

Detailed Agenda

  • Day One:
    • Lap Around WPF
    • WPF Tools ( Blend, Visual Studio 2008)
    • Graphics Subsystem
    • Layout
    • WPF Fundamentals and new concepts
      • Application Model
      • Dependency Properties
      • Trees (logical & visual)
      • Events
      • Threading
      • Resources
    • Controls
    • Styling
    • Templating
    • Q&A with instructors at end of day
  • Day Two:
    • WPF integration with Win32 and Windows Forms
    • Data binding
    • Introduction to Model-View-ViewModel
    • Commanding in M-V-VM
    • Views, Navigation and Transitions
    • Data Validation
    • Error handling, Model dialogs, Logging
    • Unit Testing
    • MVVM & LOB tips and tricks
    • Q&A with the instructors

Read more here.

And the best of all is that it is absolutely Free.

Apr
10
2009

ReSharper 4.5 released

As you might have realized following my blog, I am big fan of JetBrains ReSharper for quite some years! This tool really boost my productivity. Today they just realized ReSharper 4.5 which brings some new functionalities but also a huge improvement in performance.

What's New in ReSharper 4.5

ReSharper 4.5 delivers a great performance boost, new features and more. Read about them below or watch this Live Demo

Performance and Memory Usage Improvements

ReSharper loads and works faster and more smoothly in general, particularly on big solutions: now it takes 20 to 40 percent less time until the solution is ready for code editing. Website loading time has been reduced by 30%. Other accelerated operations include: renaming symbols, finding commonly used symbols, creating symbols from usage, and analyzing large XAML files. Memory requirements for analysis of jumbo autogenerated code files have been reduced. Read more »

Solution-Wide Code Inspections

To detect unused non-private members on the fly, we have improved our solution-wide analysis by introducing a set of specialized code inspections. They only work when you let ReSharper analyze your whole solution and help you discover: unused non-private declarations; unused return values of non-private methods; unaccessed non-private fields; unused parameters in non-private members; and more. Read more »

VB9 Support

Visual Basic .NET developers can now benefit from VB9 language support that includes implicitly typed local variables, object initializers, anonymous types, extension methods, lambda expressions, partial methods, and embedded XML. VB9 support is all around you, courtesy of new context actions, code completion, refactorings, and Parameter Info, among other supporting features. Read more »

Extended Naming Style Configuration

You can now define custom naming style settings for different languages and symbols including types, namespaces, interfaces, parameters, method properties and events, static and instance fields etc. Use them to precisely align the way ReSharper completes and generates code with your specific coding guidelines. Read more »

Other Enhancements

Go to Implementation — Jump from usage of a base type or member straight to any of its end implementations.
New and Improved Refactorings — Added Inline Field and refactored many other refactorings for greater performance.

Native MSTest Support — Finally provided natively in ReSharper on par with nUnit support.
Wider Cross-Language Capabilities — More efficient quick-fixes and context actions in many cross-language scenarios, as well as increased coverage for XAML and ASP.NET.
Smoother Language and Framework Support — Improved compatibility with F#, Compact Framework, Silverlight 2 and other languages and tools. Read more »

Download ReSharper

Apr
10
2009

ATI Drivers installation on my HP NW8440 notebook

From quite some time I had a crash when running the ATI Catalyst installer and I finally found what was the issue.

Follow the steps in the Knowledge Base (KB) article to solve the problem with the Microsoft Visual Studio mfc80u.dll or mfc80.dll module

This problem was caused by the Microsoft Visual Studio mfc80u.dll or mfc80.dll module, which was created by Microsoft Corporation.

Solution


To fix this problem, follow the steps in this online Microsoft Support Knowledge Base (KB) article:

KB961894: An application crashes after you install a product that updates the Mfc80.dll or Mfc80u.dll module

I followed the KB and then I could run again the installer without any issue.

Another good news is that ATI release now installers for notebooks. We don’t need anymore to tweak there installer using Mobility DotNET Final1.1.1.0.

For example I could find the installer for my FireGL V5200.

About Laurent

Laurent Kempé

Laurent Kempé is the editor, founder, and primary contributor of Tech Head Brothers, a French portal about Microsoft .NET technologies.

He is currently employed by Innoveo Solutions since 10/2007 as a Senior Solution Architect and certified Scrum Master.

Founder, owner and Managing Partner of Jobping, which provides a unique and efficient platform for connecting Microsoft skilled job seekers with employers using Microsoft technologies.

Laurent was awarded Most Valuable Professional (MVP) by Microsoft from April 2002 to April 2012.

JetBrains Academy Member
Certified ScrumMaster
My status

Twitter

Flickr

www.flickr.com
This is a Flickr badge showing public photos and videos from Laurent Kempé. Make your own badge here.

Month List

Page List