mvvm - Question regarding missing RemoveHandler in WPF application function -
mvvm - Question regarding missing RemoveHandler in WPF application function -
we have few scenarios in our wpf/mvvm application window beingness instanciated , opened within confines of method. simplistic example:
private sub subopenwindow dim myviewmodel = new viewmodel1 'create viewmodel window1 utilize datacontext addhandler myviewmodel.someevent, addressof subhandlesomeevent dim mywindow = new window1(viewmodel1) mywindow.show end sub private sub subhandlesomeevent 'do stuff end sub
now - debating whether or not utilize of addhandler without subsequent removehandler (normally big no-no) causing memory issues given addhandler declaration decalred , used within of subopenwindow method , there no obvious means of performing removehandler call. move viewmodel declaration more global level not seem clean.
the question is: removehandler necessary in scenario? or garbage collection clean 1 time window has been closed?
you handle window's closed event remove handler. is, reference created current class (the 1 containing handler) indeed maintain myviewmodel in memory. alternative using weak events - see here details.
wpf mvvm addhandler
Comments
Post a Comment