Is it possible to Clear (recover memory from) a specific index to a variable, while leaving other indices to...

Are the related objects in an SOQL query shared?

C# TCP server/client class

If someone else uploads my GPL'd code to Github without my permission, is that a copyright violation?

Why is it to say 'paucis post diebus'?

“The Fourier transform cannot measure two phases at the same frequency.” Why not?

How to call made-up data?

Based on what criteria do you add/not add icons to labels within a toolbar?

Getting an entry level IT position later in life

How do I show and not tell a backstory?

How do people drown while wearing a life jacket?

Is space radiation a risk for space film photography, and how is this prevented?

Why do dragons like shiny stuff?

Upper Bound for a Sum

Write The Shortest Program to Calculate Height of a Binary Tree

Is the first page of a novel really that important?

Why did the US Airways Flight 1549 passengers stay on the wings?

Is there a way to say "double + any number" in German?

In MTG, was there ever a five-color deck that worked well?

Is it uncompelling to continue the story with lower stakes?

Is there a command-line tool for converting html files to pdf?

How does Geralt transport his swords?

How can I use commands with sudo without changing owner of the files?

Why does capacitance not depend on the material of the plates?

Piece de Resistance - Introduction & Ace and A's



Is it possible to Clear (recover memory from) a specific index to a variable, while leaving other indices to the same variable untouched?







.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







3












$begingroup$


Consider the following method commonly used to clear a typical variable:



In[117]:= data = {1, 2, 3}

Out[117]= {1, 2, 3}

In[118]:= ByteCount[data]

Out[118]= 112

In[119]:= Clear[data]

In[120]:= ByteCount[data]

Out[120]= 0


No problem. Now, if I store the same information in an indexed variable, problems arise.



In[121]:= mytest[data] = {1, 2, 3}

Out[121]= {1, 2, 3}

In[122]:= ByteCount[mytest[data]]

Out[122]= 112

In[123]:= Clear[mytest[data]]

During evaluation of In[123]:= Clear::ssym: mytest[data] is not a symbol or a string.

In[124]:= ByteCount[mytest[data]]

Out[124]= 112


Is there a way to clear the values of indexed values so they don't consume memory?



My primary application requires large volumes of data to be stored in indexed variables, and at appropriate times, I would like to be able to "erase" that data from memory as my datasets are really big (multiple GBs per file).





Following initial comments, I realized I needed to re-word my initial question. (which I've done.) Taking advice from the comments, it seems Unset may be the way to go here.



Notice:



In[23]:= mytest[data] = {1, 2, 3}

Out[23]= {1, 2, 3}

In[24]:= mytest[data2] = {4, 5, 6, 7}

Out[24]= {4, 5, 6, 7}

In[6]:= ByteCount[mytest[data]]

Out[6]= 112

In[19]:= ByteCount[mytest[data2]]

Out[19]= 136

In[25]:= mytest[data] =.

In[26]:= ByteCount[mytest[data]]

Out[26]= 48

In[27]:= mytest[data]

Out[27]= mytest[data]

In[28]:= mytest[data2]

Out[28]= {4, 5, 6, 7}


As an add on, why is there a small amount of memory still attached to mytest[data] after performing the Unset operation?










share|improve this question











$endgroup$










  • 5




    $begingroup$
    ClearAll[mytest]?
    $endgroup$
    – kglr
    11 hours ago






  • 3




    $begingroup$
    Alternatively, you could use Unset: mytest[data] =.
    $endgroup$
    – Michael E2
    11 hours ago








  • 2




    $begingroup$
    Beware that the values might have also been bound to Out so you might need to clear that too if you really need the memory back.
    $endgroup$
    – b3m2a1
    11 hours ago










  • $begingroup$
    @kglr After reading your response, I realized my initial question was not defined as specifically as it should have. I need to clear memory from a specific index while leaving data associated with other indices untouched. I've modified my question and thank you for responding.
    $endgroup$
    – Todd Allen
    9 hours ago










  • $begingroup$
    @ToddAllen, so wait, what is wronog with Unset?
    $endgroup$
    – user6014
    9 hours ago


















3












$begingroup$


Consider the following method commonly used to clear a typical variable:



In[117]:= data = {1, 2, 3}

Out[117]= {1, 2, 3}

In[118]:= ByteCount[data]

Out[118]= 112

In[119]:= Clear[data]

In[120]:= ByteCount[data]

Out[120]= 0


No problem. Now, if I store the same information in an indexed variable, problems arise.



In[121]:= mytest[data] = {1, 2, 3}

Out[121]= {1, 2, 3}

In[122]:= ByteCount[mytest[data]]

Out[122]= 112

In[123]:= Clear[mytest[data]]

During evaluation of In[123]:= Clear::ssym: mytest[data] is not a symbol or a string.

In[124]:= ByteCount[mytest[data]]

Out[124]= 112


Is there a way to clear the values of indexed values so they don't consume memory?



My primary application requires large volumes of data to be stored in indexed variables, and at appropriate times, I would like to be able to "erase" that data from memory as my datasets are really big (multiple GBs per file).





Following initial comments, I realized I needed to re-word my initial question. (which I've done.) Taking advice from the comments, it seems Unset may be the way to go here.



Notice:



In[23]:= mytest[data] = {1, 2, 3}

Out[23]= {1, 2, 3}

In[24]:= mytest[data2] = {4, 5, 6, 7}

Out[24]= {4, 5, 6, 7}

In[6]:= ByteCount[mytest[data]]

Out[6]= 112

In[19]:= ByteCount[mytest[data2]]

Out[19]= 136

In[25]:= mytest[data] =.

In[26]:= ByteCount[mytest[data]]

Out[26]= 48

In[27]:= mytest[data]

Out[27]= mytest[data]

In[28]:= mytest[data2]

Out[28]= {4, 5, 6, 7}


As an add on, why is there a small amount of memory still attached to mytest[data] after performing the Unset operation?










share|improve this question











$endgroup$










  • 5




    $begingroup$
    ClearAll[mytest]?
    $endgroup$
    – kglr
    11 hours ago






  • 3




    $begingroup$
    Alternatively, you could use Unset: mytest[data] =.
    $endgroup$
    – Michael E2
    11 hours ago








  • 2




    $begingroup$
    Beware that the values might have also been bound to Out so you might need to clear that too if you really need the memory back.
    $endgroup$
    – b3m2a1
    11 hours ago










  • $begingroup$
    @kglr After reading your response, I realized my initial question was not defined as specifically as it should have. I need to clear memory from a specific index while leaving data associated with other indices untouched. I've modified my question and thank you for responding.
    $endgroup$
    – Todd Allen
    9 hours ago










  • $begingroup$
    @ToddAllen, so wait, what is wronog with Unset?
    $endgroup$
    – user6014
    9 hours ago














3












3








3





$begingroup$


Consider the following method commonly used to clear a typical variable:



In[117]:= data = {1, 2, 3}

Out[117]= {1, 2, 3}

In[118]:= ByteCount[data]

Out[118]= 112

In[119]:= Clear[data]

In[120]:= ByteCount[data]

Out[120]= 0


No problem. Now, if I store the same information in an indexed variable, problems arise.



In[121]:= mytest[data] = {1, 2, 3}

Out[121]= {1, 2, 3}

In[122]:= ByteCount[mytest[data]]

Out[122]= 112

In[123]:= Clear[mytest[data]]

During evaluation of In[123]:= Clear::ssym: mytest[data] is not a symbol or a string.

In[124]:= ByteCount[mytest[data]]

Out[124]= 112


Is there a way to clear the values of indexed values so they don't consume memory?



My primary application requires large volumes of data to be stored in indexed variables, and at appropriate times, I would like to be able to "erase" that data from memory as my datasets are really big (multiple GBs per file).





Following initial comments, I realized I needed to re-word my initial question. (which I've done.) Taking advice from the comments, it seems Unset may be the way to go here.



Notice:



In[23]:= mytest[data] = {1, 2, 3}

Out[23]= {1, 2, 3}

In[24]:= mytest[data2] = {4, 5, 6, 7}

Out[24]= {4, 5, 6, 7}

In[6]:= ByteCount[mytest[data]]

Out[6]= 112

In[19]:= ByteCount[mytest[data2]]

Out[19]= 136

In[25]:= mytest[data] =.

In[26]:= ByteCount[mytest[data]]

Out[26]= 48

In[27]:= mytest[data]

Out[27]= mytest[data]

In[28]:= mytest[data2]

Out[28]= {4, 5, 6, 7}


As an add on, why is there a small amount of memory still attached to mytest[data] after performing the Unset operation?










share|improve this question











$endgroup$




Consider the following method commonly used to clear a typical variable:



In[117]:= data = {1, 2, 3}

Out[117]= {1, 2, 3}

In[118]:= ByteCount[data]

Out[118]= 112

In[119]:= Clear[data]

In[120]:= ByteCount[data]

Out[120]= 0


No problem. Now, if I store the same information in an indexed variable, problems arise.



In[121]:= mytest[data] = {1, 2, 3}

Out[121]= {1, 2, 3}

In[122]:= ByteCount[mytest[data]]

Out[122]= 112

In[123]:= Clear[mytest[data]]

During evaluation of In[123]:= Clear::ssym: mytest[data] is not a symbol or a string.

In[124]:= ByteCount[mytest[data]]

Out[124]= 112


Is there a way to clear the values of indexed values so they don't consume memory?



My primary application requires large volumes of data to be stored in indexed variables, and at appropriate times, I would like to be able to "erase" that data from memory as my datasets are really big (multiple GBs per file).





Following initial comments, I realized I needed to re-word my initial question. (which I've done.) Taking advice from the comments, it seems Unset may be the way to go here.



Notice:



In[23]:= mytest[data] = {1, 2, 3}

Out[23]= {1, 2, 3}

In[24]:= mytest[data2] = {4, 5, 6, 7}

Out[24]= {4, 5, 6, 7}

In[6]:= ByteCount[mytest[data]]

Out[6]= 112

In[19]:= ByteCount[mytest[data2]]

Out[19]= 136

In[25]:= mytest[data] =.

In[26]:= ByteCount[mytest[data]]

Out[26]= 48

In[27]:= mytest[data]

Out[27]= mytest[data]

In[28]:= mytest[data2]

Out[28]= {4, 5, 6, 7}


As an add on, why is there a small amount of memory still attached to mytest[data] after performing the Unset operation?







error variable-definitions memory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 9 hours ago







Todd Allen

















asked 11 hours ago









Todd AllenTodd Allen

1,0345 gold badges21 silver badges30 bronze badges




1,0345 gold badges21 silver badges30 bronze badges











  • 5




    $begingroup$
    ClearAll[mytest]?
    $endgroup$
    – kglr
    11 hours ago






  • 3




    $begingroup$
    Alternatively, you could use Unset: mytest[data] =.
    $endgroup$
    – Michael E2
    11 hours ago








  • 2




    $begingroup$
    Beware that the values might have also been bound to Out so you might need to clear that too if you really need the memory back.
    $endgroup$
    – b3m2a1
    11 hours ago










  • $begingroup$
    @kglr After reading your response, I realized my initial question was not defined as specifically as it should have. I need to clear memory from a specific index while leaving data associated with other indices untouched. I've modified my question and thank you for responding.
    $endgroup$
    – Todd Allen
    9 hours ago










  • $begingroup$
    @ToddAllen, so wait, what is wronog with Unset?
    $endgroup$
    – user6014
    9 hours ago














  • 5




    $begingroup$
    ClearAll[mytest]?
    $endgroup$
    – kglr
    11 hours ago






  • 3




    $begingroup$
    Alternatively, you could use Unset: mytest[data] =.
    $endgroup$
    – Michael E2
    11 hours ago








  • 2




    $begingroup$
    Beware that the values might have also been bound to Out so you might need to clear that too if you really need the memory back.
    $endgroup$
    – b3m2a1
    11 hours ago










  • $begingroup$
    @kglr After reading your response, I realized my initial question was not defined as specifically as it should have. I need to clear memory from a specific index while leaving data associated with other indices untouched. I've modified my question and thank you for responding.
    $endgroup$
    – Todd Allen
    9 hours ago










  • $begingroup$
    @ToddAllen, so wait, what is wronog with Unset?
    $endgroup$
    – user6014
    9 hours ago








5




5




$begingroup$
ClearAll[mytest]?
$endgroup$
– kglr
11 hours ago




$begingroup$
ClearAll[mytest]?
$endgroup$
– kglr
11 hours ago




3




3




$begingroup$
Alternatively, you could use Unset: mytest[data] =.
$endgroup$
– Michael E2
11 hours ago






$begingroup$
Alternatively, you could use Unset: mytest[data] =.
$endgroup$
– Michael E2
11 hours ago






2




2




$begingroup$
Beware that the values might have also been bound to Out so you might need to clear that too if you really need the memory back.
$endgroup$
– b3m2a1
11 hours ago




$begingroup$
Beware that the values might have also been bound to Out so you might need to clear that too if you really need the memory back.
$endgroup$
– b3m2a1
11 hours ago












$begingroup$
@kglr After reading your response, I realized my initial question was not defined as specifically as it should have. I need to clear memory from a specific index while leaving data associated with other indices untouched. I've modified my question and thank you for responding.
$endgroup$
– Todd Allen
9 hours ago




$begingroup$
@kglr After reading your response, I realized my initial question was not defined as specifically as it should have. I need to clear memory from a specific index while leaving data associated with other indices untouched. I've modified my question and thank you for responding.
$endgroup$
– Todd Allen
9 hours ago












$begingroup$
@ToddAllen, so wait, what is wronog with Unset?
$endgroup$
– user6014
9 hours ago




$begingroup$
@ToddAllen, so wait, what is wronog with Unset?
$endgroup$
– user6014
9 hours ago










2 Answers
2






active

oldest

votes


















2












$begingroup$

Byte count is 64, for entry in indexed variable. Even if there is no data



Mathematica graphics



As mentioned in comment, use =. to clear specific index



Mathematica graphics






share|improve this answer









$endgroup$























    2












    $begingroup$

    Too long for a comment:



    ByteCount[mytest[data]] measures the memory required for the expression mytest[data]. The ByteCount of a Symbol is always zero; see the docs for ByteCount:




    Symbols are effectively always shared, so they give 0 byte count:




    In other words (I think), it does not count the memory required to store the symbol in the symbol/hash table.



    The OP's first ByteCount[data] computes ByteCount[{1, 2, 3}] because data evaluates to the expression {1, 2, 3} before ByteCount is called. Consider



    Trace[ByteCount@data]
    (* {{data, {1, 2, 3}},
    ByteCount[{1,2,3}],
    112} *)


    Also consider the difference between the evaluated and unevaluated data:



    data = {1, 2, 3}; 
    ByteCount /@ {data, Unevaluated@data}
    (* {112, 0} *)


    @Nasser's example ByteCount[a[1]] gives 64 bytes and the OP's ByteCount[mytest[data]] gives 48 bytes (after data is cleared). Here is an accounting of it:



    Clear[a, b];
    ByteCount@ 1
    ByteCount@ a[b]
    ByteCount@ a[1]
    (*
    16 - storage of one integer
    48 - storage of the head--argument tree expression
    64 - total
    *)


    One can carry this accounting game further. For instance, ByteCount@ 2[1]
    gives 80. However, beware that according to the docs,




    ByteCount will...often give an overestimate of the amount of memory...needed....




    Back to the principal question, which has already been answered, how to free up memory when a value is no longer needed:





    • Unset will remove a single value (definition).


    • Clear will remove all values (definitions) but not attributes, options, defaults or messages.


    • ClearAll will remove all values, attributes, options, defaults and messages.


    • Remove removes the symbol (thereby all things associated with it) from the symbol table.


    See the docs for more information. As has been noted in the comments and @Nasser's answer, Unset is the desired solution in the OP's case.






    share|improve this answer









    $endgroup$















    • $begingroup$
      Thank you for the follow-up. It is detailed responses like this that really start to peel back the "petals of ignorance." Much obliged.
      $endgroup$
      – Todd Allen
      3 hours ago














    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "387"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f203316%2fis-it-possible-to-clear-recover-memory-from-a-specific-index-to-a-variable-wh%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2












    $begingroup$

    Byte count is 64, for entry in indexed variable. Even if there is no data



    Mathematica graphics



    As mentioned in comment, use =. to clear specific index



    Mathematica graphics






    share|improve this answer









    $endgroup$




















      2












      $begingroup$

      Byte count is 64, for entry in indexed variable. Even if there is no data



      Mathematica graphics



      As mentioned in comment, use =. to clear specific index



      Mathematica graphics






      share|improve this answer









      $endgroup$


















        2












        2








        2





        $begingroup$

        Byte count is 64, for entry in indexed variable. Even if there is no data



        Mathematica graphics



        As mentioned in comment, use =. to clear specific index



        Mathematica graphics






        share|improve this answer









        $endgroup$



        Byte count is 64, for entry in indexed variable. Even if there is no data



        Mathematica graphics



        As mentioned in comment, use =. to clear specific index



        Mathematica graphics







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 9 hours ago









        NasserNasser

        61k4 gold badges93 silver badges214 bronze badges




        61k4 gold badges93 silver badges214 bronze badges




























            2












            $begingroup$

            Too long for a comment:



            ByteCount[mytest[data]] measures the memory required for the expression mytest[data]. The ByteCount of a Symbol is always zero; see the docs for ByteCount:




            Symbols are effectively always shared, so they give 0 byte count:




            In other words (I think), it does not count the memory required to store the symbol in the symbol/hash table.



            The OP's first ByteCount[data] computes ByteCount[{1, 2, 3}] because data evaluates to the expression {1, 2, 3} before ByteCount is called. Consider



            Trace[ByteCount@data]
            (* {{data, {1, 2, 3}},
            ByteCount[{1,2,3}],
            112} *)


            Also consider the difference between the evaluated and unevaluated data:



            data = {1, 2, 3}; 
            ByteCount /@ {data, Unevaluated@data}
            (* {112, 0} *)


            @Nasser's example ByteCount[a[1]] gives 64 bytes and the OP's ByteCount[mytest[data]] gives 48 bytes (after data is cleared). Here is an accounting of it:



            Clear[a, b];
            ByteCount@ 1
            ByteCount@ a[b]
            ByteCount@ a[1]
            (*
            16 - storage of one integer
            48 - storage of the head--argument tree expression
            64 - total
            *)


            One can carry this accounting game further. For instance, ByteCount@ 2[1]
            gives 80. However, beware that according to the docs,




            ByteCount will...often give an overestimate of the amount of memory...needed....




            Back to the principal question, which has already been answered, how to free up memory when a value is no longer needed:





            • Unset will remove a single value (definition).


            • Clear will remove all values (definitions) but not attributes, options, defaults or messages.


            • ClearAll will remove all values, attributes, options, defaults and messages.


            • Remove removes the symbol (thereby all things associated with it) from the symbol table.


            See the docs for more information. As has been noted in the comments and @Nasser's answer, Unset is the desired solution in the OP's case.






            share|improve this answer









            $endgroup$















            • $begingroup$
              Thank you for the follow-up. It is detailed responses like this that really start to peel back the "petals of ignorance." Much obliged.
              $endgroup$
              – Todd Allen
              3 hours ago
















            2












            $begingroup$

            Too long for a comment:



            ByteCount[mytest[data]] measures the memory required for the expression mytest[data]. The ByteCount of a Symbol is always zero; see the docs for ByteCount:




            Symbols are effectively always shared, so they give 0 byte count:




            In other words (I think), it does not count the memory required to store the symbol in the symbol/hash table.



            The OP's first ByteCount[data] computes ByteCount[{1, 2, 3}] because data evaluates to the expression {1, 2, 3} before ByteCount is called. Consider



            Trace[ByteCount@data]
            (* {{data, {1, 2, 3}},
            ByteCount[{1,2,3}],
            112} *)


            Also consider the difference between the evaluated and unevaluated data:



            data = {1, 2, 3}; 
            ByteCount /@ {data, Unevaluated@data}
            (* {112, 0} *)


            @Nasser's example ByteCount[a[1]] gives 64 bytes and the OP's ByteCount[mytest[data]] gives 48 bytes (after data is cleared). Here is an accounting of it:



            Clear[a, b];
            ByteCount@ 1
            ByteCount@ a[b]
            ByteCount@ a[1]
            (*
            16 - storage of one integer
            48 - storage of the head--argument tree expression
            64 - total
            *)


            One can carry this accounting game further. For instance, ByteCount@ 2[1]
            gives 80. However, beware that according to the docs,




            ByteCount will...often give an overestimate of the amount of memory...needed....




            Back to the principal question, which has already been answered, how to free up memory when a value is no longer needed:





            • Unset will remove a single value (definition).


            • Clear will remove all values (definitions) but not attributes, options, defaults or messages.


            • ClearAll will remove all values, attributes, options, defaults and messages.


            • Remove removes the symbol (thereby all things associated with it) from the symbol table.


            See the docs for more information. As has been noted in the comments and @Nasser's answer, Unset is the desired solution in the OP's case.






            share|improve this answer









            $endgroup$















            • $begingroup$
              Thank you for the follow-up. It is detailed responses like this that really start to peel back the "petals of ignorance." Much obliged.
              $endgroup$
              – Todd Allen
              3 hours ago














            2












            2








            2





            $begingroup$

            Too long for a comment:



            ByteCount[mytest[data]] measures the memory required for the expression mytest[data]. The ByteCount of a Symbol is always zero; see the docs for ByteCount:




            Symbols are effectively always shared, so they give 0 byte count:




            In other words (I think), it does not count the memory required to store the symbol in the symbol/hash table.



            The OP's first ByteCount[data] computes ByteCount[{1, 2, 3}] because data evaluates to the expression {1, 2, 3} before ByteCount is called. Consider



            Trace[ByteCount@data]
            (* {{data, {1, 2, 3}},
            ByteCount[{1,2,3}],
            112} *)


            Also consider the difference between the evaluated and unevaluated data:



            data = {1, 2, 3}; 
            ByteCount /@ {data, Unevaluated@data}
            (* {112, 0} *)


            @Nasser's example ByteCount[a[1]] gives 64 bytes and the OP's ByteCount[mytest[data]] gives 48 bytes (after data is cleared). Here is an accounting of it:



            Clear[a, b];
            ByteCount@ 1
            ByteCount@ a[b]
            ByteCount@ a[1]
            (*
            16 - storage of one integer
            48 - storage of the head--argument tree expression
            64 - total
            *)


            One can carry this accounting game further. For instance, ByteCount@ 2[1]
            gives 80. However, beware that according to the docs,




            ByteCount will...often give an overestimate of the amount of memory...needed....




            Back to the principal question, which has already been answered, how to free up memory when a value is no longer needed:





            • Unset will remove a single value (definition).


            • Clear will remove all values (definitions) but not attributes, options, defaults or messages.


            • ClearAll will remove all values, attributes, options, defaults and messages.


            • Remove removes the symbol (thereby all things associated with it) from the symbol table.


            See the docs for more information. As has been noted in the comments and @Nasser's answer, Unset is the desired solution in the OP's case.






            share|improve this answer









            $endgroup$



            Too long for a comment:



            ByteCount[mytest[data]] measures the memory required for the expression mytest[data]. The ByteCount of a Symbol is always zero; see the docs for ByteCount:




            Symbols are effectively always shared, so they give 0 byte count:




            In other words (I think), it does not count the memory required to store the symbol in the symbol/hash table.



            The OP's first ByteCount[data] computes ByteCount[{1, 2, 3}] because data evaluates to the expression {1, 2, 3} before ByteCount is called. Consider



            Trace[ByteCount@data]
            (* {{data, {1, 2, 3}},
            ByteCount[{1,2,3}],
            112} *)


            Also consider the difference between the evaluated and unevaluated data:



            data = {1, 2, 3}; 
            ByteCount /@ {data, Unevaluated@data}
            (* {112, 0} *)


            @Nasser's example ByteCount[a[1]] gives 64 bytes and the OP's ByteCount[mytest[data]] gives 48 bytes (after data is cleared). Here is an accounting of it:



            Clear[a, b];
            ByteCount@ 1
            ByteCount@ a[b]
            ByteCount@ a[1]
            (*
            16 - storage of one integer
            48 - storage of the head--argument tree expression
            64 - total
            *)


            One can carry this accounting game further. For instance, ByteCount@ 2[1]
            gives 80. However, beware that according to the docs,




            ByteCount will...often give an overestimate of the amount of memory...needed....




            Back to the principal question, which has already been answered, how to free up memory when a value is no longer needed:





            • Unset will remove a single value (definition).


            • Clear will remove all values (definitions) but not attributes, options, defaults or messages.


            • ClearAll will remove all values, attributes, options, defaults and messages.


            • Remove removes the symbol (thereby all things associated with it) from the symbol table.


            See the docs for more information. As has been noted in the comments and @Nasser's answer, Unset is the desired solution in the OP's case.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 8 hours ago









            Michael E2Michael E2

            157k13 gold badges215 silver badges510 bronze badges




            157k13 gold badges215 silver badges510 bronze badges















            • $begingroup$
              Thank you for the follow-up. It is detailed responses like this that really start to peel back the "petals of ignorance." Much obliged.
              $endgroup$
              – Todd Allen
              3 hours ago


















            • $begingroup$
              Thank you for the follow-up. It is detailed responses like this that really start to peel back the "petals of ignorance." Much obliged.
              $endgroup$
              – Todd Allen
              3 hours ago
















            $begingroup$
            Thank you for the follow-up. It is detailed responses like this that really start to peel back the "petals of ignorance." Much obliged.
            $endgroup$
            – Todd Allen
            3 hours ago




            $begingroup$
            Thank you for the follow-up. It is detailed responses like this that really start to peel back the "petals of ignorance." Much obliged.
            $endgroup$
            – Todd Allen
            3 hours ago


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f203316%2fis-it-possible-to-clear-recover-memory-from-a-specific-index-to-a-variable-wh%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...