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

split inside flalign

When using the Proficiency Dice optional rule, how should they be used in determining a character's Spell Save DC?

Properties: Left of the colon

How to design an effective polearm-bow hybrid?

Is there a way to improve my grade after graduation?

how to change dot to underline in multiple file-names?

What's "halachic" about "Esav hates Ya'akov"?

A verb for when some rights are not violated?

How does Rust's 128-bit integer `i128` work on a 64-bit system?

How do people drown while wearing a life jacket?

Upper Bound for a Sum

Need reasons why a satellite network would not work

Are the related objects in an SOQL query shared?

Can attackers change the public key of certificate during the SSL handshake

Is there a booking app or site that lets you specify your gender for shared dormitories?

Why is Heisenberg shown dead in Negro y Azul?

Getting Lost in the Caves of Chaos

Vectorised way to calculate mean of left and right neighbours in a vector

Can a Hogwarts student refuse the Sorting Hat's decision?

Broken bottom bracket?

Why do proponents of guns oppose gun competency tests?

Is the first page of a novel really that important?

Is it uncompelling to continue the story with lower stakes?

How do I show and not tell a backstory?



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
    8 hours ago






  • 3




    $begingroup$
    Alternatively, you could use Unset: mytest[data] =.
    $endgroup$
    – Michael E2
    8 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
    8 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
    7 hours ago










  • $begingroup$
    @ToddAllen, so wait, what is wronog with Unset?
    $endgroup$
    – user6014
    6 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
    8 hours ago






  • 3




    $begingroup$
    Alternatively, you could use Unset: mytest[data] =.
    $endgroup$
    – Michael E2
    8 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
    8 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
    7 hours ago










  • $begingroup$
    @ToddAllen, so wait, what is wronog with Unset?
    $endgroup$
    – user6014
    6 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 6 hours ago







Todd Allen

















asked 8 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
    8 hours ago






  • 3




    $begingroup$
    Alternatively, you could use Unset: mytest[data] =.
    $endgroup$
    – Michael E2
    8 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
    8 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
    7 hours ago










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












  • 5




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






  • 3




    $begingroup$
    Alternatively, you could use Unset: mytest[data] =.
    $endgroup$
    – Michael E2
    8 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
    8 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
    7 hours ago










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







5




5




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




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




3




3




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





$begingroup$
Alternatively, you could use Unset: mytest[data] =.
$endgroup$
– Michael E2
8 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
8 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
8 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
7 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
7 hours ago












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




$begingroup$
@ToddAllen, so wait, what is wronog with Unset?
$endgroup$
– user6014
6 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
      1 hour 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 6 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
              1 hour 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
              1 hour 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 5 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
              1 hour 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
              1 hour 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
            1 hour 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
            1 hour 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

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Tom Holland Mục lục Đầu đời và giáo dục | Sự nghiệp | Cuộc sống cá nhân | Phim tham gia | Giải thưởng và đề cử | Chú thích | Liên kết ngoài | Trình đơn chuyển hướngProfile“Person Details for Thomas Stanley Holland, "England and Wales Birth Registration Index, 1837-2008" — FamilySearch.org”"Meet Tom Holland... the 16-year-old star of The Impossible""Schoolboy actor Tom Holland finds himself in Oscar contention for role in tsunami drama"“Naomi Watts on the Prince William and Harry's reaction to her film about the late Princess Diana”lưu trữ"Holland and Pflueger Are West End's Two New 'Billy Elliots'""I'm so envious of my son, the movie star! British writer Dominic Holland's spent 20 years trying to crack Hollywood - but he's been beaten to it by a very unlikely rival"“Richard and Margaret Povey of Jersey, Channel Islands, UK: Information about Thomas Stanley Holland”"Tom Holland to play Billy Elliot""New Billy Elliot leaving the garage"Billy Elliot the Musical - Tom Holland - Billy"A Tale of four Billys: Tom Holland""The Feel Good Factor""Thames Christian College schoolboys join Myleene Klass for The Feelgood Factor""Government launches £600,000 arts bursaries pilot""BILLY's Chapman, Holland, Gardner & Jackson-Keen Visit Prime Minister""Elton John 'blown away' by Billy Elliot fifth birthday" (video with John's interview and fragments of Holland's performance)"First News interviews Arrietty's Tom Holland"“33rd Critics' Circle Film Awards winners”“National Board of Review Current Awards”Bản gốc"Ron Howard Whaling Tale 'In The Heart Of The Sea' Casts Tom Holland"“'Spider-Man' Finds Tom Holland to Star as New Web-Slinger”lưu trữ“Captain America: Civil War (2016)”“Film Review: ‘Captain America: Civil War’”lưu trữ“‘Captain America: Civil War’ review: Choose your own avenger”lưu trữ“The Lost City of Z reviews”“Sony Pictures and Marvel Studios Find Their 'Spider-Man' Star and Director”“‘Mary Magdalene’, ‘Current War’ & ‘Wind River’ Get 2017 Release Dates From Weinstein”“Lionsgate Unleashing Daisy Ridley & Tom Holland Starrer ‘Chaos Walking’ In Cannes”“PTA's 'Master' Leads Chicago Film Critics Nominations, UPDATED: Houston and Indiana Critics Nominations”“Nominaciones Goya 2013 Telecinco Cinema – ENG”“Jameson Empire Film Awards: Martin Freeman wins best actor for performance in The Hobbit”“34th Annual Young Artist Awards”Bản gốc“Teen Choice Awards 2016—Captain America: Civil War Leads Second Wave of Nominations”“BAFTA Film Award Nominations: ‘La La Land’ Leads Race”“Saturn Awards Nominations 2017: 'Rogue One,' 'Walking Dead' Lead”Tom HollandTom HollandTom HollandTom Hollandmedia.gettyimages.comWorldCat Identities300279794no20130442900000 0004 0355 42791085670554170004732cb16706349t(data)XX5557367