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 junkone, 04-21-2024, 07:17 AM
    9 responses
    67 views
    0 likes
    Last Post jeronymite  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    4 responses
    18 views
    0 likes
    Last Post trilliantrader  
    Started by mgco4you, Today, 09:46 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by wzgy0920, Today, 09:53 PM
    0 responses
    10 views
    0 likes
    Last Post wzgy0920  
    Started by Rapine Heihei, Today, 08:19 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X