.net - When and where to call the RemoveHandler in VB.NET? -


i working vb.net windows forms projet in .net 1.1. , have type of architecture, simplified.

public mustinherit class basetestlogic    private _timerpoll timer    public sub new(byval sym symbolfilemng, byval cfg lamptestconfig, byval daas daasmanager, byval mcf elux.wg.lpd.mcfs.vmcf)      addhandler _timerpoll.tick, addressof timerpoll_tick    end sub  end class  public class specifictestlogic   inherits basetestlogic        end class 

depending of type of test doing create instance of specific test derived basetestlogic. found after hundreds of object creations can have stackoverflow exception.

i checked code , saw forgot remove handler timer tick. question is, , when correct remove hadler?

do need implement idisposable interface in base class , removehandler in dispose?

you may go along removing handler when dispose called, purist "you shouldn't abuse idisposable purposes other disposing unmanaged resources".

another option remove handler @ finalize method.

you can feel comfortable removing handler @ several different places, if makes sense in design. removing removed handler not cause issue - unless event custom event , addhandler/removehandler implementations don't match behavior of non-custom events (which use [delegate].combinedelegate/[delegate].remove). don't tell purist friends it; won't comply.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -