I have fixed this bug, which lost about 50 bytes on each recursive call
to a function. Thanks Pascal for the timely report. The fix will be in
the upcoming J8.05 release, I understand.
Henry Rich
On 12/9/2016 9:04 PM, bill lam wrote:
I tested with the script at the script at the bottom,
initial 3370624
241920
A 5338112
445
SEVEN 5338112
241920
A 7435264
445
SEVEN 7435264
final 7434112
initial 7433856
(27x12)(20x12)(13x14)(7x10)(1x12)A
A1 7435264
(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN
SEVEN1 7435264
(27x12)(20x12)(13x14)(7x10)(1x12)A
A1 7435264
(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN
SEVEN1 7435264
final 7434112
initial 7433856
(27x12)(20x12)(13x14)(7x10)(1x12)A
A2 7433856
(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN
SEVEN2 7433856
(27x12)(20x12)(13x14)(7x10)(1x12)A
A2 7433856
(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN
SEVEN2 7433856
final 7434112
For Pascal's f2, each iteration increased memory without release.
Compared the initial and final values for the last 2 control
tests, apparently echo is not responsible for memory leak.
The for_loop structure add a little overhead but should be
released after iteration.
Perhaps the culprit is recursion inside iteration loop.
the script is,
foo=: 3 : 0
echo 'initial ',":7!:0''
for_i. i.2 do.
echo f2 '(27x12)(20x12)(13x14)(7x10)(1x12)A'
echo 'A ', ":7!:0''
echo f2 '(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN'
echo 'SEVEN ', ":7!:0''
end.
''
)
bar=: 3 : 0
echo 'initial ',":7!:0''
for_i. i.2 do.
echo '(27x12)(20x12)(13x14)(7x10)(1x12)A'
echo 'A1 ', ":7!:0''
echo '(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN'
echo 'SEVEN1 ', ":7!:0''
end.
''
)
foobar=: 3 : 0
echo 'initial ',":7!:0''
echo '(27x12)(20x12)(13x14)(7x10)(1x12)A'
echo 'A2 ', ":7!:0''
echo '(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN'
echo 'SEVEN2 ', ":7!:0''
echo '(27x12)(20x12)(13x14)(7x10)(1x12)A'
echo 'A2 ', ":7!:0''
echo '(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN'
echo 'SEVEN2 ', ":7!:0''
''
)
f2 =: 3 : 0
o =. 0
while. (# y) > e =. ')' i.~ y do.
b =. '(' i:~ e {. y
i =. ". every 'x' cut y{~ b + >:i. <:e -b
o =. o + b + f2 i expand (>:e )}. y
y =. ({.i) }. (>:e) }. y
end.
o + #y
)
expand =: */@:[ $ {.@[ {. ]
foo''
echo 'final ',":7!:0''
bar''
echo 'final ',":7!:0''
foobar''
echo 'final ',":7!:0''
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm