wpf - How to prevent a memory leak when displaying an image by binding to a bytearray? -


i have large treeview full of textboxes, each tooltip containing unique image. image stored in property bytearray , bind it. every time new tooltip displayed more memory used.

i scaling image, doesn't address root of problem. if there way free memory used after tooltip no longer displayed?

<textblock.tooltip>     <stackpanel>         <image maxwidth="650"                maxheight="400"                source="{binding imageasbytearray}"/>         <textblock text="{binding filepath, stringformat='full path: {0}'}" />     </stackpanel> </textblock.tooltip> 

the tooltip can set framework element, dynamically create object behind scenes:

<textblock tooltip={binding tooltip} /> 

then view model or code behind dynamically create object , handle loaded/unloaded event capture when tooltip displays.

i've done below canvas case want add other children besides image:

var tooltipcanvas = new canvas(); var img = new image();  tooltipcanvas.children.add(img); tooltipcanvas.width = 500; tooltipcanvas.height = 500; tooltipcanvas.loaded += tooltip_loaded; tooltipcanvas.unloaded += tooltip_unloaded; 

then populate image source time image shown using loaded , unloaded event handlers:

private void tooltip_loaded(object sender, routedeventargs e) {     var canvas = sender canvas;     var img = canvas.children[0] image;     img.source = /* image bytes */; }  private void tooltip_unloaded(object sender, routedeventargs e) {     var canvas = sender canvas;     var img = canvas.children[0] image;     img.source = null; } 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -