Announcement

Collapse
No announcement yet.

How to clear an array variable

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

  • How to clear an array variable

    Once the ALengths array is run in the bInit routine it is no longer needed.

    How do I delete the array to release resources?

    This is just a simple example.

    Thanks

    wayne

    PHP Code:
    debugClear();
    function 
    preMain(){
        
    setPriceStudy(true);
    }
    var 
    bInit false
    var 
    vFontColor9 Color.red;
    var 
    vFontColor13 Color.blue;
    var 
    vFontColor56 Color.green;
    var 
    ALengths = new Array("9","13","56");
    var 
    PlotArray = new Array();

    function 
    main(){
       if ( 
    bInit == false ) { 
            for (
    i=0i<=ALengths.length-1i++){
                var 
    TempFColor "vFontColor" ALengths[i]   
                
    debugPrintln(" - " TempFColor);
                
    setDefaultBarFgColor(eval(TempFColor), i);
                var 
    TempEMA "Study" ALengths[i] + " = ema(" ALengths[i] + ")";
                eval(
    TempEMA)
                
    TempEMASeries "Study" ALengths[i] + " = getSeries(" "Study" ALengths[i] + ")";
                eval(
    TempEMASeries);
                
    PlotArray.push(eval("Study" ALengths[i]));
            }
            
    bInit true;
        }
     return (
    PlotArray);   


  • #2
    Re: How to clear an array variable

    Hi Wayne,

    Set the global variable equal to null. Better yet, do not make it a global variable, rather, make it a local variable inside your bInit conditional. It will automatically be garbage collected.

    Originally posted by waynecd
    Once the ALengths array is run in the bInit routine it is no longer needed.

    How do I delete the array to release resources?

    This is just a simple example.

    Thanks

    wayne

    PHP Code:
    debugClear();
    function 
    preMain(){
        
    setPriceStudy(true);
    }
    var 
    bInit false
    var 
    vFontColor9 Color.red;
    var 
    vFontColor13 Color.blue;
    var 
    vFontColor56 Color.green;
    var 
    ALengths = new Array("9","13","56");
    var 
    PlotArray = new Array();

    function 
    main(){
       if ( 
    bInit == false ) { 
            for (
    i=0i<=ALengths.length-1i++){
                var 
    TempFColor "vFontColor" ALengths[i]   
                
    debugPrintln(" - " TempFColor);
                
    setDefaultBarFgColor(eval(TempFColor), i);
                var 
    TempEMA "Study" ALengths[i] + " = ema(" ALengths[i] + ")";
                eval(
    TempEMA)
                
    TempEMASeries "Study" ALengths[i] + " = getSeries(" "Study" ALengths[i] + ")";
                eval(
    TempEMASeries);
                
    PlotArray.push(eval("Study" ALengths[i]));
            }
            
    bInit true;
        }
     return (
    PlotArray);   

    Comment


    • #3
      Hi Steve,

      For the bInit example I'll use a local variable. For those whithin Main or support functions I'll set them to null.

      As usual you go one step further than asked.

      Thanks.

      Wayne

      Comment


      • #4
        Hi Wayne,

        You are most welcome, your remarks are appreciated.

        Comment

        Working...
        X