First of all I suspect you are running Mathematica 10.0.0 and are experiencing these issues:
- Potential pollution of Global` context in fresh kernelPotential pollution of Global` context in fresh kernel
- Is garbage collection broken in version 10.0.0?Is garbage collection broken in version 10.0.0?
In version 10.0.1 I get:
Names["Global`*"] {}
And then:
mydummy[x_, y_, model_] := Module[{ans, j}, ans = Sum[x[[j]], {j, 1, y}]]; Names["Global`*"] {"ans", "ans$", "j", "j$", "model", "mydummy", "x", "y"}
The remaining names can all be explained as expected behavior. Every Symbol name that appears that does not correspond to an existing Symbol in the $ContextPath
is created in the current $Context. See:
- Local variables in Module leak into the Global contextLocal variables in Module leak into the Global context
This explains {"ans", "j", "model", "mydummy", "x", "y"}.
The remaining two: {"ans$", "j$"} are more tricky; I believe they are created by the automatic renaming mechanism that applies to nested scoping constructs, here SetDelayed and Module. See:
- Enforcing correct variable bindings and avoiding renamings for conflicting variables in nested scoping constructsEnforcing correct variable bindings and avoiding renamings for conflicting variables in nested scoping constructs
I shall try to address all of your question on a point-by-point basis if I have time. I think those links should give you plenty to read for the moment, and right now it is time for me to eat. :-)