Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to dispose of plots and brushes?

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

    How to dispose of plots and brushes?

    I understand that .Net takes care of garbage collection on its own, but I'm not very good at programming and as such I run into issues with my code from time to time where the memory usage starts racking up, especially during testing when I'm constantly reloading/rerunning the script.

    Is there a proper way to manually dispose of brushes/plots/whatever else that indicators would normally use?

    I see in the help guide that Dispose() can be called on for draw tools and sharpDX brushes, but can anything like that be done with system windows media brushes/solidcolorbrushes, plots, backbrush?
    If so, a sample code snippet would help.


    thanks!

    #2
    Hello gubbar924,

    Thanks for your post.

    You can call Dispose() in State.Terminated that will dispose of anything that is left over.

    For example:

    else if (State == State.Terminated)
    Dispose();

    Comment


      #3
      I don't think so.
      eDanny
      NinjaTrader Ecosystem Vendor - Integrity Traders

      Comment


        #4
        Hi Paul,

        Thank you for the quick reply, I'll update my code based on the ninjascript best practices section and add Dispose() as you suggested.


        Thanks!

        Comment


          #5
          Hello. tried Dispose() according to advice and manual:

          Code:
          else if (State == State.Terminated) 
          {	
             Dispose();
          }
          and got error:CS103, "The name 'Dispose' does not exist in the current context".

          How to fight this disaster?
          fx.practic
          NinjaTrader Ecosystem Vendor - fx.practic

          Comment


            #6
            Hello fx.practic,

            Thanks for your reply.

            With reference to best practices, you would use something like:

            Code:
            else if (State == State.Terminated)
              {
                // only dispose of object if it has been configured
                if (configured)
                {
                    myObject.Dispose();
                }
              }
            Reference: http://ninjatrader.com/support/helpG..._practices.htm (Look under state management practices)

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            156 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            90 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            140 views
            2 likes
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            130 views
            1 like
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            107 views
            0 likes
            Last Post CarlTrading  
            Working...
            X