Click here to Skip to main content
15,892,927 members
Home / Discussions / WPF
   

WPF

 
QuestionRe: Labelprint on Thermotransfer Pin
Eddy Vluggen9-Feb-22 3:13
professionalEddy Vluggen9-Feb-22 3:13 
QuestionWPF c# onStartUp() view model problem with multiple data inputs Pin
StealthRT5-Feb-22 7:31
StealthRT5-Feb-22 7:31 
AnswerRe: WPF c# onStartUp() view model problem with multiple data inputs Pin
Gerry Schmitz5-Feb-22 18:16
mveGerry Schmitz5-Feb-22 18:16 
AnswerRe: WPF c# onStartUp() view model problem with multiple data inputs Pin
Kevin Marois21-Feb-22 11:29
professionalKevin Marois21-Feb-22 11:29 
QuestionWpf System.Windows.Media.ImageSourcesConverter cannot be applied Pin
StealthRT1-Feb-22 16:08
StealthRT1-Feb-22 16:08 
AnswerRe: Wpf System.Windows.Media.ImageSourcesConverter cannot be applied Pin
Richard Deeming1-Feb-22 21:49
mveRichard Deeming1-Feb-22 21:49 
GeneralRe: Wpf System.Windows.Media.ImageSourcesConverter cannot be applied Pin
StealthRT2-Feb-22 2:39
StealthRT2-Feb-22 2:39 
GeneralRe: Wpf System.Windows.Media.ImageSourcesConverter cannot be applied Pin
Richard Deeming2-Feb-22 2:44
mveRichard Deeming2-Feb-22 2:44 
Question(beginner) There must be a better way (TextBlock properties) Pin
Maximilien26-Jan-22 5:08
Maximilien26-Jan-22 5:08 
AnswerRe: (beginner) There must be a better way (TextBlock properties) Pin
Richard Deeming26-Jan-22 5:33
mveRichard Deeming26-Jan-22 5:33 
GeneralRe: (beginner) There must be a better way (TextBlock properties) Pin
Maximilien26-Jan-22 9:10
Maximilien26-Jan-22 9:10 
QuestionConverting a byte[] to a ImageSource means huge memory leak Pin
Starwer24-Jan-22 11:42
Starwer24-Jan-22 11:42 
AnswerRe: Converting a byte[] to a ImageSource means huge memory leak Pin
Gerry Schmitz24-Jan-22 16:15
mveGerry Schmitz24-Jan-22 16:15 
GeneralRe: Converting a byte[] to a ImageSource means huge memory leak Pin
Starwer24-Jan-22 19:58
Starwer24-Jan-22 19:58 
GeneralRe: Converting a byte[] to a ImageSource means huge memory leak Pin
Gerry Schmitz24-Jan-22 21:26
mveGerry Schmitz24-Jan-22 21:26 
GeneralRe: Converting a byte[] to a ImageSource means huge memory leak Pin
Starwer25-Jan-22 7:56
Starwer25-Jan-22 7:56 
AnswerRe: Converting a byte[] to a ImageSource means huge memory leak Pin
Richard Deeming25-Jan-22 21:51
mveRichard Deeming25-Jan-22 21:51 
GeneralRe: Converting a byte[] to a ImageSource means huge memory leak Pin
Starwer26-Jan-22 9:10
Starwer26-Jan-22 9:10 
GeneralRe: Converting a byte[] to a ImageSource means huge memory leak Pin
Gerry Schmitz27-Jan-22 6:33
mveGerry Schmitz27-Jan-22 6:33 
GeneralRe: Converting a byte[] to a ImageSource means huge memory leak Pin
Starwer27-Jan-22 20:29
Starwer27-Jan-22 20:29 
GeneralRe: Converting a byte[] to a ImageSource means huge memory leak Pin
lmoelleb3-Feb-22 4:58
lmoelleb3-Feb-22 4:58 
GeneralRe: Converting a byte[] to a ImageSource means huge memory leak Pin
Starwer5-Feb-22 0:28
Starwer5-Feb-22 0:28 
Thanks for your answer.

I've tried the fllowing:
stream.Length = 0;
stream.Capacity = 0;


But I coudn't access those properties from a MemoryStream.
So I've actually followed your advice and developped my own Stream implementation. This allowed to track what was called at least. This unfortunately didn't solve the problem. I could only see that the Close() function was called, that I could clear the Buffer that was stored there. However the finalized never gets called, giving a hint that the parent ImageSource or Image never get freed either.
Moreover, using my own Stream prevents me from freezing the ImageSource (I don't know why).

Here follows the implementation of the Stream I used:
public class ManagedMemoryStream : Stream
 {
     private int Id;
     private static int Index = 0;
     private static int Counter = 0;

     private byte[]? Buffer;

     public override bool CanRead => true;

     public override bool CanSeek => false;

     public override bool CanWrite => false;

     public override long Length => _Length;
     private long _Length;

     public override long Position { get; set; }

     public override void Close()
     {
         System.Diagnostics.Debug.WriteLine($"ManagedMemoryStream: Close {Id} / {Counter}");
         base.Close();
         Dispose(true);
         Buffer = null;
     }

     public ManagedMemoryStream(byte[] buffer)
     {
         Id = Index++;
         System.Diagnostics.Debug.WriteLine($"ManagedMemoryStream: Construct {Id} / {++Counter}");

         Buffer = buffer;
         _Length = Buffer.Length;

     }


     ~ManagedMemoryStream()
     {
         System.Diagnostics.Debug.WriteLine($"ManagedMemoryStream: Finalize {Id} / {--Counter}");
         Dispose(false);
     }

     public override void Flush()
     {
         System.Diagnostics.Debug.WriteLine($"ManagedMemoryStream: Flush {Id} / {Counter}");
     }

     public override int Read(byte[] buffer, int offset, int count)
     {
         //System.Diagnostics.Debug.WriteLine($"ManagedMemoryStream: Read {Id}, {offset}, {count} / {Counter}");
         if (count == 0 || Buffer is null) return 0;
         int remaining = (int)(Buffer.Length - Position);
         if (count > remaining) count = remaining;

         Array.Copy(Buffer, Position, buffer, offset, count);
         Position += count;
         _Length -= count;

         return count;
     }

     public override long Seek(long offset, SeekOrigin origin)
     {
         throw new NotImplementedException();
     }

     public override void SetLength(long value)
     {
         throw new InvalidOperationException();
     }

     public override void Write(byte[] buffer, int offset, int count)
     {
         throw new InvalidOperationException();
     }
 }

GeneralRe: Converting a byte[] to a ImageSource means huge memory leak Pin
lmoelleb6-Feb-22 3:27
lmoelleb6-Feb-22 3:27 
AnswerRe: Converting a byte[] to a ImageSource means huge memory leak Pin
Starwer30-Jan-22 5:04
Starwer30-Jan-22 5:04 
GeneralRe: Converting a byte[] to a ImageSource means huge memory leak Pin
Gerry Schmitz30-Jan-22 5:23
mveGerry Schmitz30-Jan-22 5:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.