简体   繁体   中英

Why did MVVMLight's RelayCommand use WeakAction

I noticed that GalaSoft.MvvmLight.CommandWpf.RelayCommand<T> using WeakAction<T> .

this design consideration was surprising to me and I did a little further investigation.
while browsing the web, I came across this blog post which strengthen my suspicion, but did not answer my original question as to "Why?"

Why would GalaSoft intentionally use WeakAction instead of plain Action allow the functions to get Garbage Collected?

Thank you.

Why would GalaSoft intentionally use WeakAction instead of plain Action allow the functions to get Garbage Collected?

Most probably to prevent the commands(s) from keeping the owner(s) of the action(s) alive and cause memory leaks in an MvvmLight application.

Using a WeakAction<T> , the owner is still eligible for garbage collection despite the fact the command may be not as there is no strong reference between the command and the owner of the action.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM