index > Windows Presentation Foundation ("Avalon") > Memory Leak problem when using bitmap image as tooltip?

Memory Leak problem when using bitmap image as tooltip?

My code:

Image img = new Image();

BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water lilies.jpg");
bi.EndInit();
img.Source = bi;
btn1.ToolTip = img; //btn1 is a Button

Symptom:

Every time when the tooltip of "btn1" shows, some memory is consumed and will not be released later.

So, is it the problem of my code or the winfx?

Thanks a lot.




Rguo
Rguo

I don't think that's a WinFX problem. I believe that, as long as the btn1 element exists, its property value (in this case, the bitmap image) is stored in memory.

So, if you really want it gone, set btn1.tooltip=null when the tooltip closes. Then that variable will get munched up by the GC. when it loses scope (i.e. when the method ends).

Blackice

By default, the BitmapCacheOption is set ot "OnDemand". This means that the image will be held onto since we need to be able to get to the image bits. Can you try the following and see if this helps:

Image img = new Image();

BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water lilies.jpg");

bi.CacheOption = BitmapCacheOption.OnLoad;
bi.EndInit();
img.Source = bi;
btn1.ToolTip = img; //btn1 is a Button

Robert A. Wlodarczyk - MSFT
reply 3

You can use google to search for other answers

 

More Articles

• How to apply Sorting in a List view control???
• Strange flicker on window display ...
• Animating a camera
• Aplying DataTemplate to a Panel
• How to extend functionality using custom control or custom class ...
• Problem of RelativeSource in DataBinding
• attaching events with a polyline
• Catching Exception at App Level
• custom control problems
• Need example of custom assembly.
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Image button source
• Possible BlockCollection bug - Need clar
• How do we display Items in table format
• emulating a mouse in WPF
• can XBAP XAML reference isoloated storate
• dragging a grid - problem with positioning
• .NET 3.0 and Expression Interactive Desi
• CheckBox and binding path
• PropertyGrid
• Adorners: How to show stylable help and
• Navigation Window: Can it be Like a web
• WPF + Deskbar Questions
• Remove Security Bubble when displaying S
• BindingExpression with XPath='Profiles/P
• 3D animation Performance

Hot Articles

• How to prevent TabControl from doing mul
• Navigate URL in RSS Feed threw Xaml??
• Dock Panel System
• Z-order
• Interactive Designer XBAP Questions
• winfx wizard framework
• Custom Popup Placement in control template
• Working with events that are coming from
• Problem in Listview
• How to transfer(Upload) file to remote s
• XBAP application not picking relative path
• How to create an instance of ObservableC
• Binding to Combobox.Text when IsSynchron
• ContextMenu for GridViewColumn
• DataGrid

Recommend Articles

• Howto: make the Enter key work like the
• bitmapeffect bug?
• Changing default editor for XAML
• Databinding controls
• Raising an event when a Storyboard hits
• The name 'InitializeComponent' does not
• Resource Dictionaries & Templates
• Bug Fixes
• Feedback please: WPF for LOB application
• Code formatting on Forum
• Activate Deactivate Triggers
• setting properties after animation was a
• frameworkelementfactory grid columndefin
• how to keep doc file in document viewer
• How to resize the font based on the wind