Table::itform: Argument 1 at position 2 does not have the correct form for an iterator. >>
At least Mathematica 9 requires an iterator there:
Table[1, 3]
Table::itform: Argument 1 at position 2 does not have the correct form for an iterator.
Table[1, {3}]
{1, 1, 1}
Well, yes, this effect is somewhat typical - you find it e.g. whenever you use Module (with or without local variables):
Module does not eat memory so agressively. So I like to use a `hybrid' variant of the procedure:
myFindMinimum2[func_, p0_List] := Module[{svars, vars, sol},
svars = "{";
Do[svars = svars <> "p" <> ToString[i] <> ",", {i, Length[p0]}];
vars = ToExpression[StringDrop[svars, -1] <> "}"];
sol = FindMinimum[func[vars], Transpose[{vars, p0}]];
{sol[[1]], vars /. sol[[2]]}
]
MemoryInUse[]
Do[myFindMinimum2[func, {1, 1, 1, 1}], {1000}]
MemoryInUse[]
% - %%%
35267376
35269064
1688
But I still look for more elegant solutions.