Skip to content

Commit 476a74b

Browse files
committed
CHANGE: more aggressive recycle native
related to: Oldes/Rebol-issues#1128
1 parent df09076 commit 476a74b

File tree

6 files changed

+32
-14
lines changed

6 files changed

+32
-14
lines changed

src/core/c-do.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ x*/ static REBINT Do_Args_Light(REBVAL *func, REBVAL *path, REBSER *block, REBCN
822822
// Check for recycle signal:
823823
if (GET_FLAG(sigs, SIG_RECYCLE)) {
824824
CLR_SIGNAL(SIG_RECYCLE);
825-
Recycle();
825+
Recycle(FALSE);
826826
}
827827

828828
#ifdef NOT_USED_INVESTIGATE
@@ -2333,6 +2333,6 @@ xx*/ REBVAL *Do_Path(REBVAL **path_val, REBVAL *val)
23332333

23342334
// Cleanup stack and memory:
23352335
DS_RESET;
2336-
Recycle();
2336+
Recycle(FALSE);
23372337
return 0; //result;
23382338
}

src/core/m-gc.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,12 @@ static void Mark_Series(REBSER *series, REBCNT depth);
637637

638638
/***********************************************************************
639639
**
640-
*/ REBCNT Recycle(void)
640+
*/ REBCNT Recycle(REBOOL all)
641641
/*
642642
** Recycle memory no longer needed.
643643
**
644+
** When all is TRUE, then infant series are not protected!
645+
**
644646
***********************************************************************/
645647
{
646648
REBINT n;
@@ -689,12 +691,15 @@ static void Mark_Series(REBSER *series, REBCNT depth);
689691
// Mark the last MAX_SAFE "infant" series that were created.
690692
// We must assume that infant blocks are valid - that they contain
691693
// no partially valid datatypes (that are under construction).
692-
for (n = 0; n < MAX_SAFE_SERIES; n++) {
693-
REBSER *ser;
694-
if (NZ(ser = GC_Infants[n])) {
695-
//Dump_Series(ser, "Safe Series");
696-
Mark_Series(ser, 0);
697-
} else break;
694+
if (!all) {
695+
for (n = 0; n < MAX_SAFE_SERIES; n++) {
696+
REBSER *ser;
697+
if (NZ(ser = GC_Infants[n])) {
698+
//Dump_Series(ser, "Safe Series");
699+
Mark_Series(ser, 0);
700+
}
701+
else break;
702+
}
698703
}
699704

700705
// Mark all root series:

src/core/m-pools.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ const REBPOOLSPEC Mem_Pool_Spec[MAX_POOLS] =
326326
REBPOL *pool;
327327
REBCNT pool_num;
328328

329-
// if (GC_TRIGGER) Recycle();
329+
// if (GC_TRIGGER) Recycle(FALSE);
330330

331331
length *= SERIES_WIDE(series);
332332
pool_num = FIND_POOL(length);
@@ -395,7 +395,7 @@ const REBPOOLSPEC Mem_Pool_Spec[MAX_POOLS] =
395395

396396
ASSERT(wide != 0, RP_BAD_SERIES);
397397

398-
// if (GC_TRIGGER) Recycle();
398+
// if (GC_TRIGGER) Recycle(FALSE);
399399

400400
series = (REBSER *)Make_Node(SERIES_POOL);
401401
length *= wide;

src/core/n-system.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
SET_INT32(TASK_BALLAST, 0);
9797
}
9898

99-
count = Recycle();
99+
count = Recycle(TRUE);
100100

101101
DS_Ret_Int(count);
102102
return R_RET;

src/mezz/mezz-debug.reb

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dt: delta-time: function [
1717
block [block!]
1818
][
1919
; force GC, so there is less chance that it is fired in `do block`
20-
recycle recycle ; 2x => first mark, second sweep
20+
recycle
2121
start: stats/timer
2222
do block
2323
stats/timer - start
@@ -29,7 +29,7 @@ dp: delta-profile: func [
2929
/local start end adjust
3030
][
3131
; first force GC
32-
recycle recycle
32+
recycle
3333
; than count adjustments for empty code
3434
adjust: copy end: stats/profile
3535
do []

src/tests/units/series-test.r3

+13
Original file line numberDiff line numberDiff line change
@@ -2673,4 +2673,17 @@ Rebol [
26732673

26742674
;-- VECTOR related tests moved to %vector-test.r3
26752675

2676+
===start-group=== "RECYCLE"
2677+
--test-- "recycle"
2678+
;@@ https://github.com/Oldes/Rebol-issues/issues/1128
2679+
recycle ;; force GC
2680+
count: stats ;; store current memory usage
2681+
make string! 5000000 ;; create large unreferenced series
2682+
--assert all [
2683+
stats >= (count + 5000000) ;; check that memory usage increased
2684+
recycle ;; force GC
2685+
stats = count ;; check if memory usage decreased
2686+
]
2687+
===end-group===
2688+
26762689
~~~end-file~~~

0 commit comments

Comments
 (0)