Login Page - Create Account

Support Board


Date/Time: Fri, 10 Jan 2025 20:24:52 +0000



Post From: Custom study with sierrachart functions : Memory leak

[2016-09-26 17:42:57]
User612903 - Posts: 51
Hi,

I've tested a little and simple custom dll, and i realise there is already a little leak of memory.

Do i need to freeup some memory after calling your functions ?
Or do i need to clean the SCSubgraphRef ?

Thanks for helping.

Here is my code :


SCSFExport scsf_GlobalTrendlines(SCStudyInterfaceRef sc)
{
  
  SCSubgraphRef SMA50 = sc.Subgraph[0];
  SCSubgraphRef SMA200 = sc.Subgraph[1];
  SCSubgraphRef ATRGRAPH = sc.Subgraph[2];
  SCSubgraphRef ZIGZAG = sc.Subgraph[3];

  //SCInputRef SMA50Length = sc.Input[0]; FOR SETTING  

  // Set configuration variables
  if (sc.SetDefaults)
  {
    // Set the configuration and defaults

    sc.GraphName = "Global Trendlines";
    sc.StudyDescription = "";

    // Set the region to draw the graph in. Region zero is the main
    // price graph region.
    sc.GraphRegion = 0;
    
    sc.AutoLoop = 1;

    sc.AlertOnlyOncePerBar = true;

    // During development set this flag to 1, so the DLL can be modified. When development is completed, set it to 0 to improve performance.
    sc.FreeDLL = 1;

    //sc.AddMessageToLog("FK All set", 1);

    // Must return before doing any data processing if sc.SetDefaults is set
    return;
  }
  
  
  // only process at the close of the bar; if it has not closed don't do anything
  if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_NOT_CLOSED)
  {
    return;
  }

  //SMA50
  SMA50.Name = "SMA50";
  SMA50.PrimaryColor = COLOR_YELLOW;
  SMA50.DrawStyle = DRAWSTYLE_POINT;
  SMA50.LineWidth = 1;
  sc.SimpleMovAvg(sc.Close, SMA50, 50);

  //SMA200
  SMA200.Name = "SMA200";
  SMA200.DrawStyle = DRAWSTYLE_POINT;
  SMA200.PrimaryColor = COLOR_PURPLE;
  SMA200.LineWidth = 1;
  sc.SimpleMovAvg(sc.Close, SMA200, 200);

  //ATR GRAPH
  ATRGRAPH.Name = "XATR";
  ATRGRAPH.DrawStyle = DRAWSTYLE_IGNORE;
  ATRGRAPH.LineWidth = 2;
  ATRGRAPH.PrimaryColor = COLOR_BLUE;
  sc.ATR(sc.BaseDataIn, ATRGRAPH, 400, MOVAVGTYPE_SIMPLE);

  //ZIGZAG
  ZIGZAG.Name = "ZIGZAG";
  ZIGZAG.DrawStyle = DRAWSTYLE_LINE;
  ZIGZAG.LineWidth = 3;
  ZIGZAG.LineStyle = LINESTYLE_DOT;
  ZIGZAG.PrimaryColor = COLOR_PURPLE;
  sc.ZigZag2(sc.High, sc.Low, ZIGZAG, 2, 0.0003, sc.ArraySize - 500);
  
  return;  
  
}