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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            567 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            330 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            548 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            548 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X