Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to spot memory leakage

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

    How to spot memory leakage

    Hello

    I have coded a strategy that is rather complex and using several third parties stuff. While its logic seems to be working rather fine, leaving it running results in ever increasing RAM consumption that I am not able to resolve. So for now I have to restart ninja every now and then.

    Any idea what to look for in my code ? Any best practices/guidelines on how to use and release resources in my own code, or on how to find which third party component is causing this ?

    Thanks !

    #2
    Originally posted by tickling View Post
    Hello

    I have coded a strategy that is rather complex and using several third parties stuff. While its logic seems to be working rather fine, leaving it running results in ever increasing RAM consumption that I am not able to resolve. So for now I have to restart ninja every now and then.

    Any idea what to look for in my code ? Any best practices/guidelines on how to use and release resources in my own code, or on how to find which third party component is causing this ?

    Thanks !
    If the third-party components are protected dll's, you will have to test them individually to see which one is the culprit. If you have access to the code, then you want to see if you are creating a lot of new objects whose memory never gets freed, especially if COBC is false.

    How are you calling these third-party components? Using named instances, or relying on NT scanning (the magic code generated at the bottom of indicators), to find the correct instance in each case?
    Last edited by koganam; 06-09-2012, 02:15 PM.

    Comment


      #3
      I have no access to the source code of the third parties. I am calling them using named instances. Should I release those explicitly at the end of each OnBarUpdate() ? Doesn't Ninja/.Net take care of it ?

      What is COBS ?

      Comment


        #4
        Originally posted by tickling View Post
        I have no access to the source code of the third parties. I am calling them using named instances. Should I release those explicitly at the end of each OnBarUpdate() ? Doesn't Ninja/.Net take care of it ?

        What is COBS ?
        If you are using a single named instance for each call, then it would appear that the leak may well be in the components. That is, unless it is actually in your code.

        The simplest way to find out if it is in the components rather than your code, given that you do not have the source code for the components, is unfortunately going to be loading each one of the components and waiting long enough to see which one is causing your memory leak. It may be possible to speed things up by testing using a speeded-up market replay session.

        COBS was meant to be COBC. I have corrected it in the initial post where it was used.

        Comment


          #5
          tickling,

          COBC is "CalculateOnBarClose", its a setting that changes when your indicators are called, either tick-by-tick or on closing of a bar.

          What Koganam is suggesting is that these other indicators may be causing a memory increase. You could disable them in your code temporarily to help isolate where the memory issue is coming from. For example, create some dummie value where you use that indicator and test. Then, test again with it enabled and check the memory usage.

          .NET does have garbage collection which frees up memory that is not in use, however the indicator may be using up a lot of memory still.
          Adam P.NinjaTrader Customer Service

          Comment


            #6
            Thank you Adam and Koganam. I guess no easy magic Much obliged

            Comment


              #7
              Have you investigated if the memory consumption is related to stored market data?

              C# (.NET Framework) employs automatic memory management, which frees developers from manually allocating and freeing the memory occupied by objects.You can read more about automatic garbage collection in the CSharp Language Reference, paragraph 3.9.

              Do you have MaximumBarsLookback set to Infinite?

              http://ninjatrader.com/support/helpG...rslookback.htm

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              666 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              377 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              110 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              575 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              580 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X