Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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();
    Paul H.NinjaTrader Customer Service

    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)
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by yertle, Today, 08:38 AM
            2 responses
            7 views
            0 likes
            Last Post yertle
            by yertle
             
            Started by dappa, Today, 09:18 AM
            0 responses
            2 views
            0 likes
            Last Post dappa
            by dappa
             
            Started by bill2023, Yesterday, 08:51 AM
            4 responses
            22 views
            0 likes
            Last Post bltdavid  
            Started by trilliantrader, Today, 08:16 AM
            3 responses
            9 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by NinjaTrader_ChelseaB, 01-08-2017, 06:59 PM
            79 responses
            19,662 views
            5 likes
            Last Post zrobfrank  
            Working...
            X