Analysing memory leaks - step breakdown

Created at 18 May 2023, 02:38
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
J.

J.Lo

Joined 23.10.2021

Analysing memory leaks - step breakdown
18 May 2023, 02:38


Here are some of my findings 

step 1: I open ctrader and select the "Trade View"

The memory used is very good and stable

step 2: I switch to the "Automate view" (note: visual studio 2022 is running)

ctrader immediately jumps up in RAM but holds stable

step 3: i create an run a unit test on my robot (i dont believe this builds a new algo file)

ctrader does not like this. memory does not go down

step 5: write another unit test

ctrader memory jumps up but does not release

 


@J.Lo
Replies

Spotware
18 May 2023, 09:08

Dear trader,

Thanks for reporting this issue. In order to investigate this further, we would need the source code of the cBot you are using.

Best regards,

cTrader Team


@Spotware

J.Lo
19 May 2023, 02:13 ( Updated at: 21 Dec 2023, 09:23 )

RE:

Spotware said:

Dear trader,

Thanks for reporting this issue. In order to investigate this further, we would need the source code of the cBot you are using.

Best regards,

cTrader Team

Here you go .. i just created a sample. simply add a new unit test and run it.. Although not as extreme as my real bot, you should notice the RAM going up but never coming back down 

I can't see a place to attach a zip file *shrug

just used a sample 


using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleRSIcBot : Robot
    {
        [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("Source", Group = "RSI")]
        public DataSeries Source { get; set; }

        [Parameter("Periods", Group = "RSI", DefaultValue = 14)]
        public int Periods { get; set; }

        private RelativeStrengthIndex rsi;

        protected override void OnStart()
        {
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
        }

        protected override void OnTick()
        {
            if (rsi.Result.LastValue < 30)
            {
                Close(TradeType.Sell);
                Open(TradeType.Buy);
            }
            else if (rsi.Result.LastValue > 70)
            {
                Close(TradeType.Buy);
                Open(TradeType.Sell);
            }
        }

        private void Close(TradeType tradeType)
        {
            foreach (var position in Positions.FindAll("SampleRSI", SymbolName, tradeType))
                ClosePosition(position);
        }

        private void Open(TradeType tradeType)
        {
            var position = Positions.Find("SampleRSI", SymbolName, tradeType);
            var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);

            if (position == null)
                ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "SampleRSI");
        }
    }
}

 

 

Then the Unit Test Project 

namespace TestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {

            Assert.IsTrue(true);
        }

        [TestMethod]
        public void TestMethod2()
        {
            for(int i=0; i < 100000000; i++)
            {
                string debug = i.ToString();
            }
            Assert.IsTrue(true);
        }
    }
}

 


@J.Lo

ncel01
24 May 2023, 15:15

Hi J.Lo,

Although Spotware's approach to this issue is always the same (requesting for cBot code), it has become evident that this is a cTrader core issue, which has nothing to do with any cBots, as you just proved, like many other traders did in the past. 

This issue has been reported since 2013, so don't expect it to get fixed anytime soon.

Also, don't expect any reply from Spotware after it becomes clear in your post that cBots are not the issue.


@ncel01

Spotware
24 May 2023, 15:39

Dear J.Lo,

Thanks for the code sample. We were able to reproduce this behavior and it will be investigated further by the product team

Best regards,

cTrader Team


@Spotware

ncel01
24 May 2023, 19:57

Case closed :)


@ncel01

J.Lo
25 May 2023, 01:48

RE:

Spotware said:

Dear J.Lo,

Thanks for the code sample. We were able to reproduce this behavior and it will be investigated further by the product team

Best regards,

cTrader Team

Thanks..

side note. simply saving a change to the *.sln /  *cproj file also produces this behavior (i.e. doesn't need a build)


@J.Lo

J.Lo
16 Jul 2023, 00:54

RE: RE:

Thanks! This seems to be fixed in 4.8  *thumbs up emoji

 


@J.Lo