Well, I give it a try to answer your question.
Share works is, that all symbols in the symbol table are checked, and those with the same values are cross-referenced. So you can not expect that your
e is reduced but if there is another
e2) with exact the same value, it will get cross referenced.
Let's check this assumption. The Integral of
x^66 Sin[x]^44 takes about ~500MB:
ByteCount[tmp1 = Integrate[x^35 Sin[x]^44, x]]
To get the size of the Mathematica subexpression we can use
LeafCount[tmp2 = Integrate[x^35 Sin[x]^44, x]]
tmp2 do have exactly the same value. Let's check the memory in use:
If we call now
Share there should be a considerable amount of reduced memory consumption:
If we subtract these values, we may expect that we see the reduction of (
tmp1 + tmp2) into one
tmp for instance. The problem is we don't since
MemoryInUse does involve state changes and so it is nearly impossible to get a discrete state.
If we try to call
tmp2 we will realise, that
Share is not able to save any memory for
tmp2, since it is already cross-referenced with
This is how
Share basically works.
Hope this helps.