Cyberiafreak

"Fortunate are those who take the first steps.” ― Paulo Coelho

WPF memory leak issues & fixes.

I hope some of you might’ve already gone through the recent Redgate article on memory leak.

RICKY LEEKS PRESENTSTHE TOP 5 – WPF AND SILVERLIGHT GOTCHAS-Pdf (by Redgate)

Src : http://www.red-gate.com/products/dotnet-development/ants-memory-profiler/learning-memory-management/resources/RickyLeeks-MisconceptionsLong.pdf

Key take away,

1)   UnRegister events  – .net funda

2)  DataBinding issue – <Grid Name=”mainGrid”>

<TextBlock Name=”txtMainText” Text=”{Binding ElementName=mainGrid, Path=Children.Count}” />

</Grid>

Issue:-  The condition will only occur if the bound property is a PropertyDescriptor property, as Children.Count is. This is because, in order to detect when a PropertyDescriptor property

changes, the framework has to subscribe to the ValueChanged event, which in turn sets up a strong reference chain.

Description :

-If the binding is marked as OneTime, the bound property is a DependencyProperty, or the object implements INotifyPropertyChanged, then the issue won’t occur.

-In the case of OneTime binding this is because, as the name suggests, it doesn’t need to detect property changes, with the binding occurring once from data source to consumer.

Solution: (many ways)

–          Add a DependencyProperty to the page/window which simply returns the value of the required PropertyDescriptor property  (or )   Make the binding OneTime – Text=”{Binding Path=Salary, Mode=OneTime}”/    (or)   Add the following line of code on exit from the page:

BindingOperations.ClearBinding(txtMainText, TextBlock.TextProperty); This simply clears the binding and removes the reference.

3)      Static Events – Statics, once referenced, remain for the duration of the app domain execution

4)      Command Binding – Child window command binding references in Main window need to be explicitly removed on close of Child windows.

Ex: mainWindow.main.CommandBindings.Remove(cutCmdBinding);

5)      Dispatcher Leak – .net funda

6)      Textbox Undo leak – new

Issue :- Problem is to do with the TextBox control and UNDO. TextBoxes have built-in undo functionality, enabling a user to undo their changes to a text box

Fix:- You can limit the behavior of the undo stack by either switching it off using: textBox1.IsUndoEnabled=false;

This limits the number of actions that can be undone, in this case to 100; By default the setting is -1 which limits the number of actions only by the amount of memory available. Setting the value to zero switches undo off. –

<Textbox UndoLimit=-1 Width=100 Height=20 …./>

Note: For couple of weeks, I tried redgate for WPF profiling – Honestly I m not able to understand or make out what exactly steeling my memory with regards to WPF. It points to a WPF class and goes on and goes on as a chain. As a developer, I feel difficult to understand the redgate’s chart diagram ( was expecting it will point me /refer to a class where the leak has happened.. but full of WPF classes ). any comment?

Memory leak by WPF Resources : http://weblogs.asp.net/lkempe/archive/2009/04/17/memory-leak-with-wpf-resources.aspx

Memory leak by WPF Animation: http://blog.ramondeklein.nl/index.php/2009/02/20/memory-leak-with-wpf-animations/

Advertisements

August 22, 2011 Posted by | Uncategorized | Leave a comment

What happened to Application.Restart() in WPF?

Its crazy, I just found that there is no way you can do Application.Restart. You have to do 2 thing to achieve this.
1) Kill the current process/Application.Shutdown
2) Re-Launch the same application.

Details here-
http://robrelyea.wordpress.com/2007/07/24/application-restart-for-wpf/

August 16, 2011 Posted by | Uncategorized | | Leave a comment

Microsoft All-In-One Code Framework August Code Sample Updates

Wow, Here is the neat sample code snippets which you can depend on needy time.
I was looking for code piece to determine the underlying OS is of 32 bit or 64 bit…on googling.. i found many flavors to detect this..but none seems to work with different processor architecture and OS.
Finally I found this page, tested. – very neat and ready to use.
http://1code.codeplex.com/SourceControl/changeset/view/39074#842775

More collection at -http://1code.codeplex.com/

August 12, 2011 Posted by | Uncategorized | | Leave a comment

What is Pitchbook?

I overheard in meeting about this phrase often used, “Pitchbook”…hmm not facebook 😉

What is Pitchbook – read from Investopedia –http://www.investopedia.com/terms/p/pitchbook.asp

In nutshell(src:google) –

Def1: – “A marketing tool created and used by an investment firm. A firm will create this book filled with information about the firm, and then use this as a tool when attracting new clients for the firm. These books will often include general information about the company, broad financial information describing their achievements, and specific stories about special events or situations the firm has encountered”.

Def2:- “A fund manager’s guidebook on how to inform potential investors about getting involved in investments and what type of investments meets the client’s needs at the current time. For example, a fund manager may have specific guidelines on how to talk to clients who want to learn more about investing for retirement.”

August 7, 2011 Posted by | Uncategorized | Leave a comment

   

%d bloggers like this: