12

Bug introduced in 10.0.1 and fixed in 10.0.2


In Mathematica 10, the documentation still states that a symbol with attribute Temporary will automatically be removed when it is no longer needed. Now consider

Module[{a}, Information[a]]

=> (* Global\`a$105933 Attributes[a$105933]={Temporary} *)

This a$ variable is not exported from the Module and therefore not needed any more. However, in Mathematica 10 it is not removed:

Names["Global`a$*"]

=> (* {a$105933} *)

This looks like a minor bug to me.

mmal
  • 3,508
  • 2
  • 18
  • 38
Fred Simons
  • 10,181
  • 18
  • 49
  • 2
    According to this post (see the accepted answer) : "One problem with local functions created by Module is that these symbols won't be automatically garbage-collected when Module finishes (if they have DownValues, SubValues or UpValues. OwnValues are fine), and so may lead to memory leaks. To avoid that, one can Clear these symbols inside Module before returning the result." – SquareOne Oct 29 '14 at 11:42
  • @SquareOne Yes, that is a very good post on localization. But it does not apply here, I did not make a local function. Clearing the variable in the Module should be (and is in earlier versions) superfluous. – Fred Simons Oct 29 '14 at 12:02
  • Concerning the post, I understood that the problem concerned Symbols in general, not only functions. Anyway, this post dates back to January 2012, so it corresponds to version 8 ?? When you say "earlier versions", what versions are included ? – SquareOne Oct 29 '14 at 14:20
  • Anyway, OK, I have reproduced your "bug" in version 10.0.1. and not in version 9. However, it seems to be related to the function Ìnformation only (?). If you try the example given in the Doc for Temporary, i.e :Module[{b}, Print[b]; Attributes[b]], and Names["Globalb$*"], the symbolb` was removed ... – SquareOne Oct 29 '14 at 14:28
  • By the way, just try to enable the Suggestion Bar and do the tests again ... Whether you use Information or no, a new symbol is created in the global context : in your example it is a$, in mine b$. This is true for v9 or v10 ! (This is related to the already reported "Suggestion Bar bug"). – SquareOne Oct 29 '14 at 14:42
  • I use this example already many years in one of my courses, so I think it goes back to at least version 6. But I cannot test that any more. I did almost the same test as you did with the same result and therefore the same feeling that somehow it has to do with the function Information. – Fred Simons Oct 29 '14 at 15:01
  • @SquareOne Is this a duplicate of my own report? (58375). There does remain a$ but not the localized versions e.g. a$105933. In other words the name space does not grow with each call to Module. – Mr.Wizard Jan 15 '15 at 00:28
  • @Mr.Wizard Not a duplicate. This seems rather related to Information function only. See also Alexey answer below. – SquareOne Jan 15 '15 at 01:09
  • @SquareOne Okay. I don't have 10.0.1 installed to confirm this, but I'll mark it as a bug. – Mr.Wizard Jan 15 '15 at 01:19

1 Answers1

9

I have checked it in versions 7.0.1, 8.0.4 and 10.0.1 (the Suggestion bar is turned off). The bug is present only in v.10.0.1, both v.7.0.1 and 8.0.4 return {"a"} after evaluating Names["Global`*"]:

screenshot

Moreover, if one adds a definition to the symbol a, the definition is not removed in v.10.0.1:

Remove["Global`*"]
Module[{a}, Information[a]; a = 1];
Symbol /@ Names["Global`*"]
Module[{a = 2}, Information[a];];
Symbol /@ Names["Global`*"]
{a, 1}

{a, 1, 2}

So it seems to be another v10 Module bug.

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
  • 2
    The behaviour has changed for me with v.10.0.2 (OS X 10.9.5) : when adding the defintions, now only {a} is returned (instead of {a, 1} or {a, 1, 2}. – SquareOne Jan 15 '15 at 01:12