Attached propedrties in WPF and event wiring -
i have attached property (e.g. capitalizing text inside textbox). obvoiusly must subscribe textbox's textchanged event capitalize every time text updates.
public class capitalize { // enabling/disabling capitalization public static readonly dependencyproperty enabledproperty; private static void onenabledchanged( dependencyobject d, dependencypropertychangedeventargs e) { var tb = d textbox; if ((bool)e.newvalue) { tb.textchanged += new textchangedeventhandler(tb_textchanged); } else { tb.textchanged -= new textchangedeventhandler(tb_textchanged); } } }
as see add event handlers textbox (if understand correctly) creates strong reference. mean because of strong ref gc cannot collect textbox? if yes - @ point should unwire event textbox can collected?
the reference goes other way around, i.e. text box holds reference event handler. there no possibility memory leaks.
Comments
Post a Comment