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 bmartz, 03-12-2024, 06:12 AM
            5 responses
            32 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Started by Aviram Y, Today, 05:29 AM
            4 responses
            13 views
            0 likes
            Last Post Aviram Y  
            Started by algospoke, 04-17-2024, 06:40 PM
            3 responses
            28 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by gentlebenthebear, Today, 01:30 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by cls71, Today, 04:45 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X