Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

When State.Terminated does not quite clean up.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    When State.Terminated does not quite clean up.

    Just something that I found for those of us where State.Terminated leaves some EventHandlers running because the GC has not yet figured out that cleanup is needed. We end up with what looks like a memory leak, and probably is one.

    Anyhow, I started investigating and came across this: https://msdn.microsoft.com/en-us/lib...v=vs.100).aspx

    The really interesting part is the last paragraph, as it gives us an alternative way to actually attach to NT events using a Weak Event Pattern. I am beginning to get more and more impressed with this c# thing.
    One interesting aspect of the weak event pattern is that you can implement the pattern against an event that is not part of your code base. From the perspective of the source, the way that handlers are attached to its event does not differ, and is controlled by the WeakEventManager. You only need to define a WeakEventManager for that event, and then account for that event as part of the ReceiveWeakEvent logic on any prospective listener that wants to use the weak event pattern to listen to that event.
    (emphasis mine)

    #2
    Good call, thanks for sharing!

    We actually use this in the SuperDOM columns to subscribe to the MarketDepth events, rather than use a virtual OnMarketDepth() for a different reason, but also addressed the GC issue as well when closing down:

    MatthewNinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by i019945nj, 12-14-2023, 06:41 AM
    3 responses
    60 views
    0 likes
    Last Post i019945nj  
    Started by TraderBCL, Today, 04:38 AM
    2 responses
    17 views
    0 likes
    Last Post TraderBCL  
    Started by martin70, 03-24-2023, 04:58 AM
    14 responses
    106 views
    0 likes
    Last Post martin70  
    Started by Radano, 06-10-2021, 01:40 AM
    19 responses
    610 views
    0 likes
    Last Post Radano
    by Radano
     
    Started by thanajo, 05-04-2021, 02:11 AM
    4 responses
    471 views
    0 likes
    Last Post tradingnasdaqprueba  
    Working...
    X