Memory is never released. Can't understand even with a profiler.Hi, <br/> <br/> call the following code several times : Memory is NEVER released. Why ?? Thnaks !<br/>         void SignPicture(string filePath)<br/>         {<br/>             DoIncrust(filePath);<br/> <br/>             GC.Collect();<br/>             GC.WaitForPendingFinalizers();<br/>             GC.Collect();<br/> <br/>             File.Delete(filePath);<br/> <br/>             File.Move(&quot;c:/result.jpg&quot;, filePath);<br/>             return;<br/>         }<br/> <br/>         private static void DoIncrust(string filePath)<br/>         {<br/> <br/>             MemoryStream mem;<br/>             byte[] buffer = File.ReadAllBytes(filePath);<br/>             // by reading the data into an in-memory buffer, we prevent the file from being read in the UI thread <br/>             // -- which speeds up access dramatically!<br/>             mem = new MemoryStream(buffer);<br/> <br/>             BitmapImage original = new BitmapImage();<br/>             original.BeginInit();<br/>             original.CacheOption = BitmapCacheOption.None;<br/>             original.StreamSource = mem;<br/>             original.EndInit();<br/> <br/>             MemoryStream mem2;<br/>             byte[] buffer2 = File.ReadAllBytes(&quot;c:/signature.png&quot;);<br/>             mem2 = new MemoryStream(buffer2);<br/> <br/>             BitmapImage signature = new BitmapImage();<br/>             signature.BeginInit();<br/>             signature.CacheOption = BitmapCacheOption.None;<br/>             signature.StreamSource = mem2;<br/>             signature.EndInit();<br/> <br/>             Image ori = new Image();<br/>             ori.Source = original;<br/>             Image sign = new Image();<br/>             sign.Source = signature;<br/> <br/>             Grid signaGrid = new Grid();<br/> <br/>             double percent = 0.50;<br/> <br/>             double mywidth, myheight;<br/> <br/>             ComputeWidthHeight(original, out mywidth, out myheight);<br/> <br/>             double ratio = (double)mywidth / (double)myheight;<br/>             double vwidth = percent;<br/>             double vheight = vwidth / ratio;<br/> <br/>             double otherwidth = 1.0 - vwidth;<br/>             double otherheight = 1.0 - vheight;<br/> <br/>             RowDefinition rd = new RowDefinition();<br/>             rd.Height = new GridLength(otherheight, GridUnitType.Star);<br/>             RowDefinition rd1 = new RowDefinition();<br/>             rd1.Height = new GridLength(vheight, GridUnitType.Star);<br/>             signaGrid.RowDefinitions.Add(rd);<br/>             signaGrid.RowDefinitions.Add(rd1);<br/> <br/>             ColumnDefinition cd = new ColumnDefinition();<br/>             cd.Width = new GridLength(otherwidth, GridUnitType.Star);<br/>             ColumnDefinition cd1 = new ColumnDefinition();<br/>             cd1.Width = new GridLength(vwidth, GridUnitType.Star);<br/>             signaGrid.ColumnDefinitions.Add(cd);<br/>             signaGrid.ColumnDefinitions.Add(cd1);<br/> <br/>             // Add the image<br/>             Grid.SetRow(ori, 0);<br/>             Grid.SetColumn(ori, 0);<br/>             Grid.SetRowSpan(ori, 2);<br/>             Grid.SetColumnSpan(ori, 2);<br/>             signaGrid.Children.Add(ori);<br/> <br/>             // Add the signature image<br/>             Grid.SetRow(sign, 1);<br/>             Grid.SetColumn(sign, 1);<br/>             signaGrid.Children.Add(sign);<br/> <br/>             // Render everything<br/>             RenderTargetBitmap bmp = new RenderTargetBitmap(original.PixelWidth, original.PixelHeight,<br/>                 original.DpiX, original.DpiY, PixelFormats.Pbgra32);<br/> <br/>             signaGrid.Measure(new Size(original.Width, original.Height));<br/>             signaGrid.Arrange(new Rect(0, 0, original.Width, original.Height));<br/> <br/>             bmp.Render(signaGrid);<br/> <br/>             JpegBitmapEncoder encoder = new JpegBitmapEncoder();<br/>             BitmapFrame bf = BitmapFrame.Create(bmp);<br/> <br/>             encoder.Frames.Add(bf);<br/>             FileStream stream;<br/>             stream = new FileStream(&quot;c:/result.jpg&quot;, FileMode.Create);<br/>             encoder.Save(stream);<br/>             stream.Flush();<br/>             stream.Close();<br/>             stream.Dispose();<br/>             ori.Source = null;<br/>             sign.Source = null;<br/>             signaGrid.RowDefinitions.Clear();<br/>             signaGrid.ColumnDefinitions.Clear();<br/>             bmp.Clear();<br/>             buffer = null;<br/>             buffer2 = null;<br/>             mem.Dispose();<br/>             mem2.Dispose();<br/>             bf = null;<br/>             encoder.Frames.Clear();<br/>         }<br/> <br/>         private static void ComputeWidthHeight(BitmapImage original, out double mywidth, out double myheight)<br/>         {<br/>             if (original.PixelWidth &gt; original.PixelHeight)<br/>             {<br/>                 // Paysage<br/>                 mywidth = original.PixelWidth;<br/>                 myheight = original.PixelHeight;<br/>             }<br/>             else<br/>             {<br/>                 // Portrait<br/>                 mywidth = original.PixelHeight;<br/>                 myheight = original.PixelWidth;<br/>             }<br/>         }<br/>© 2009 Microsoft Corporation. All rights reserved.Thu, 09 Jul 2009 09:24:19 Zefb6c656-0564-4a78-8174-c3fec0b8641bhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#efb6c656-0564-4a78-8174-c3fec0b8641bhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#efb6c656-0564-4a78-8174-c3fec0b8641bXavierPhttp://social.msdn.microsoft.com/Profile/en-US/?user=XavierPMemory is never released. Can't understand even with a profiler.Hi, <br/> <br/> call the following code several times : Memory is NEVER released. Why ?? Thnaks !<br/>         void SignPicture(string filePath)<br/>         {<br/>             DoIncrust(filePath);<br/> <br/>             GC.Collect();<br/>             GC.WaitForPendingFinalizers();<br/>             GC.Collect();<br/> <br/>             File.Delete(filePath);<br/> <br/>             File.Move(&quot;c:/result.jpg&quot;, filePath);<br/>             return;<br/>         }<br/> <br/>         private static void DoIncrust(string filePath)<br/>         {<br/> <br/>             MemoryStream mem;<br/>             byte[] buffer = File.ReadAllBytes(filePath);<br/>             // by reading the data into an in-memory buffer, we prevent the file from being read in the UI thread <br/>             // -- which speeds up access dramatically!<br/>             mem = new MemoryStream(buffer);<br/> <br/>             BitmapImage original = new BitmapImage();<br/>             original.BeginInit();<br/>             original.CacheOption = BitmapCacheOption.None;<br/>             original.StreamSource = mem;<br/>             original.EndInit();<br/> <br/>             MemoryStream mem2;<br/>             byte[] buffer2 = File.ReadAllBytes(&quot;c:/signature.png&quot;);<br/>             mem2 = new MemoryStream(buffer2);<br/> <br/>             BitmapImage signature = new BitmapImage();<br/>             signature.BeginInit();<br/>             signature.CacheOption = BitmapCacheOption.None;<br/>             signature.StreamSource = mem2;<br/>             signature.EndInit();<br/> <br/>             Image ori = new Image();<br/>             ori.Source = original;<br/>             Image sign = new Image();<br/>             sign.Source = signature;<br/> <br/>             Grid signaGrid = new Grid();<br/> <br/>             double percent = 0.50;<br/> <br/>             double mywidth, myheight;<br/> <br/>             ComputeWidthHeight(original, out mywidth, out myheight);<br/> <br/>             double ratio = (double)mywidth / (double)myheight;<br/>             double vwidth = percent;<br/>             double vheight = vwidth / ratio;<br/> <br/>             double otherwidth = 1.0 - vwidth;<br/>             double otherheight = 1.0 - vheight;<br/> <br/>             RowDefinition rd = new RowDefinition();<br/>             rd.Height = new GridLength(otherheight, GridUnitType.Star);<br/>             RowDefinition rd1 = new RowDefinition();<br/>             rd1.Height = new GridLength(vheight, GridUnitType.Star);<br/>             signaGrid.RowDefinitions.Add(rd);<br/>             signaGrid.RowDefinitions.Add(rd1);<br/> <br/>             ColumnDefinition cd = new ColumnDefinition();<br/>             cd.Width = new GridLength(otherwidth, GridUnitType.Star);<br/>             ColumnDefinition cd1 = new ColumnDefinition();<br/>             cd1.Width = new GridLength(vwidth, GridUnitType.Star);<br/>             signaGrid.ColumnDefinitions.Add(cd);<br/>             signaGrid.ColumnDefinitions.Add(cd1);<br/> <br/>             // Add the image<br/>             Grid.SetRow(ori, 0);<br/>             Grid.SetColumn(ori, 0);<br/>             Grid.SetRowSpan(ori, 2);<br/>             Grid.SetColumnSpan(ori, 2);<br/>             signaGrid.Children.Add(ori);<br/> <br/>             // Add the signature image<br/>             Grid.SetRow(sign, 1);<br/>             Grid.SetColumn(sign, 1);<br/>             signaGrid.Children.Add(sign);<br/> <br/>             // Render everything<br/>             RenderTargetBitmap bmp = new RenderTargetBitmap(original.PixelWidth, original.PixelHeight,<br/>                 original.DpiX, original.DpiY, PixelFormats.Pbgra32);<br/> <br/>             signaGrid.Measure(new Size(original.Width, original.Height));<br/>             signaGrid.Arrange(new Rect(0, 0, original.Width, original.Height));<br/> <br/>             bmp.Render(signaGrid);<br/> <br/>             JpegBitmapEncoder encoder = new JpegBitmapEncoder();<br/>             BitmapFrame bf = BitmapFrame.Create(bmp);<br/> <br/>             encoder.Frames.Add(bf);<br/>             FileStream stream;<br/>             stream = new FileStream(&quot;c:/result.jpg&quot;, FileMode.Create);<br/>             encoder.Save(stream);<br/>             stream.Flush();<br/>             stream.Close();<br/>             stream.Dispose();<br/>             ori.Source = null;<br/>             sign.Source = null;<br/>             signaGrid.RowDefinitions.Clear();<br/>             signaGrid.ColumnDefinitions.Clear();<br/>             bmp.Clear();<br/>             buffer = null;<br/>             buffer2 = null;<br/>             mem.Dispose();<br/>             mem2.Dispose();<br/>             bf = null;<br/>             encoder.Frames.Clear();<br/>         }<br/> <br/>         private static void ComputeWidthHeight(BitmapImage original, out double mywidth, out double myheight)<br/>         {<br/>             if (original.PixelWidth &gt; original.PixelHeight)<br/>             {<br/>                 // Paysage<br/>                 mywidth = original.PixelWidth;<br/>                 myheight = original.PixelHeight;<br/>             }<br/>             else<br/>             {<br/>                 // Portrait<br/>                 mywidth = original.PixelHeight;<br/>                 myheight = original.PixelWidth;<br/>             }<br/>         }<br/>Sat, 27 Jun 2009 19:43:45 Z2009-06-27T19:43:45Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#3d54fe44-f708-4fb0-8cce-225e4f504e28http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#3d54fe44-f708-4fb0-8cce-225e4f504e28Mark Salsberyhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mark%20SalsberyMemory is never released. Can't understand even with a profiler.Found another filed issue on Connect - this one states a leak will be fixed in future versions... <br/><br/><a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=410590">WPF RenderTargetBitmap still leaking, and badly!</a><br/><hr class="sig"> Mark Salsbery Microsoft MVP - Visual C++ Sat, 27 Jun 2009 20:03:18 Z2009-06-27T20:03:18Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#8203ffbd-31e3-45f7-adda-2d1ccbd09b70http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#8203ffbd-31e3-45f7-adda-2d1ccbd09b70XavierPhttp://social.msdn.microsoft.com/Profile/en-US/?user=XavierPMemory is never released. Can't understand even with a profiler.This one is a real showstopper to me. Any workarounds ? <br/> <br/> It's going hard to wait for next release to get it fixed !!<br/> <br/> HELP !<br/> <br/> Thanks !<br/>Sat, 27 Jun 2009 20:27:30 Z2009-06-27T20:27:30Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#72521442-0ce6-4695-bb02-38af93c71235http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#72521442-0ce6-4695-bb02-38af93c71235Ray M_http://social.msdn.microsoft.com/Profile/en-US/?user=Ray%20M_Memory is never released. Can't understand even with a profiler.<a href="http://support.microsoft.com/kb/967634/en-us">KB967634</a> might just be the fix you need.Sat, 27 Jun 2009 21:08:27 Z2009-06-27T21:08:27Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#eff27efa-4edb-49e1-a401-ef6bdf17a568http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#eff27efa-4edb-49e1-a401-ef6bdf17a568XavierPhttp://social.msdn.microsoft.com/Profile/en-US/?user=XavierPMemory is never released. Can't understand even with a profiler.Hi Ray,<br/> <br/> May be... But I'm doing WPF on my leisure time and can't afford to pay for any support ! It seems the .dll are not free to download.<br/> <br/> And I would prefer a workaround rather than this...<br/> <br/> Thanks anyway !<br/>Sun, 28 Jun 2009 18:14:42 Z2009-06-28T18:14:42Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#1820c446-5ff3-43e0-b2bd-1bbaa9b558d6http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#1820c446-5ff3-43e0-b2bd-1bbaa9b558d6Ray M_http://social.msdn.microsoft.com/Profile/en-US/?user=Ray%20M_Memory is never released. Can't understand even with a profiler.If there was a work around it would have been mentioned in the KB article, you usually have to go though support to get the hotfixes cause well they are usually not as well tested as service packs and using serveral fixes that all replace the same dll can give undesired results. support will probably have a better talk explaining the risks but as long as you understand hotfixes are not risk free <a href="http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=967634">go nuts</a>Sun, 28 Jun 2009 22:40:14 Z2009-06-28T22:40:14Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#1bea00d0-2cd0-4c48-836a-4225be9ec292http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#1bea00d0-2cd0-4c48-836a-4225be9ec292Bruce.Zhouhttp://social.msdn.microsoft.com/Profile/en-US/?user=Bruce.ZhouMemory is never released. Can't understand even with a profiler.Hi XavierP,<br/> <br/> As the KB indicates, the hotfix still needs additional test which I think is the reason the download link is not directly in that article. Ray is right, hotfix is not risk free. Besides, the article also recommends waiting for next release if you are not severely affect by this problem.<br/> <br/> Best regards,<br/> Bruce Zhou<hr class="sig">Please mark the replies as answers if they help and unmark if they don't.Tue, 30 Jun 2009 11:12:38 Z2009-06-30T11:12:38Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#f4ea77fb-0cd3-4e38-908b-ef039dd09f22http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#f4ea77fb-0cd3-4e38-908b-ef039dd09f22XavierPhttp://social.msdn.microsoft.com/Profile/en-US/?user=XavierPMemory is never released. Can't understand even with a profiler.Hi Bruce,<br/> <br/> I'm impacted but I'll disable some features in my app.  :-(<br/> <br/> When is expected a another service pack for .Net 3.5 ? I'm still a big fan of WPF but this bug really annoys me.<br/> <br/> Thanks.<br/>Wed, 01 Jul 2009 15:15:14 Z2009-07-01T15:15:14Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#96acb651-66c8-4080-82ca-40380efb2bf3http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#96acb651-66c8-4080-82ca-40380efb2bf3Bruce.Zhouhttp://social.msdn.microsoft.com/Profile/en-US/?user=Bruce.ZhouMemory is never released. Can't understand even with a profiler.Hi XavierP,<br/><br/>Totally understand your feeling. Sorry for the trouble this issue brought. Currently, I do not know when the next service pack will be released either.<br/><br/>Actually, I have the hotfix in my machine, but since it needs additional tests, I suggest you wait for the next service pack. If you really can't wait, maybe I can send it to you through email.  Besides, I need to know the version of your operating system.<br/><br/>Best regards,<br/>Bruce Zhou<br/><br/><br/><hr class="sig">Please mark the replies as answers if they help and unmark if they don't.Thu, 02 Jul 2009 02:28:46 Z2009-07-02T02:28:46Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#79b91e1c-2261-4d0b-a5d7-36232dc2db81http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#79b91e1c-2261-4d0b-a5d7-36232dc2db81XavierPhttp://social.msdn.microsoft.com/Profile/en-US/?user=XavierPMemory is never released. Can't understand even with a profiler.Hi Bruce,<br/> <br/> I'm using  Vista French edition 32 bits.<br/> When is the next service pack scheduled ?<br/> <br/> Thanks.<br/>Sat, 04 Jul 2009 17:00:52 Z2009-07-04T17:00:52Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#3cf1e804-0615-4235-b6a9-8ac35142a96bhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/efb6c656-0564-4a78-8174-c3fec0b8641b#3cf1e804-0615-4235-b6a9-8ac35142a96bBruce.Zhouhttp://social.msdn.microsoft.com/Profile/en-US/?user=Bruce.ZhouMemory is never released. Can't understand even with a profiler.Hi XavierP,<br/> <br/> Sorry, I've no idea with the plan of the service pack now. But I think it will not be long.<br/> <br/> Best regards,<br/> Bruce Zhou<hr class="sig">Please mark the replies as answers if they help and unmark if they don't.Sun, 05 Jul 2009 02:09:24 Z2009-07-05T02:09:24Z