Skip to content

Commit ee8479c

Browse files
committed
refactor(MainTransformer): Make manual GC interval a static variable.
1 parent bedfa1e commit ee8479c

File tree

3 files changed

+4
-15
lines changed

3 files changed

+4
-15
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* feat(`MainTransformer`): Manual garbage collector.
1010
* feat(`ObjectToObjectTransformer`): Option to disable lazy loading.
1111
* feat(`ObjectToObjectTransformer`): Option to disable target value reading.
12+
* refactor(`MainTransformer`): Make manual GC interval a static variable.
1213

1314
## 0.7.3
1415

src/Context/MapperOptions.php

-13
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,13 @@
1818
*/
1919
final readonly class MapperOptions
2020
{
21-
public int $manualGcInterval;
22-
2321
/**
2422
* @param boolean $enableLazyLoading Enable or disable lazy loading.
2523
* @param boolean $enableTargetValueReading If disabled, values on the target side will not be read, and assumed to be null.
26-
* @param integer|null $manualGcInterval Performs garbage collection manually every n `MainTransformer` invocation. If not provided, and lazy loading is active, it is automatically set to 1000 to fix memory leak.
2724
*/
2825
public function __construct(
2926
public bool $enableLazyLoading = true,
3027
public bool $enableTargetValueReading = true,
31-
?int $manualGcInterval = null,
3228
) {
33-
if ($manualGcInterval === null) {
34-
if ($enableLazyLoading) {
35-
$this->manualGcInterval = 1000;
36-
} else {
37-
$this->manualGcInterval = 0;
38-
}
39-
} else {
40-
$this->manualGcInterval = $manualGcInterval;
41-
}
4229
}
4330
}

src/MainTransformer/MainTransformer.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
class MainTransformer implements MainTransformerInterface
3838
{
39+
public static int $manualGcInterval = 10000;
3940
private static int $runCounter = 1;
4041

4142
public function __construct(
@@ -91,8 +92,8 @@ public function transform(
9192

9293
// if manual garbage collection interval is set, run it
9394

94-
if (($manualGcInterval = $context(MapperOptions::class)?->manualGcInterval) > 0) {
95-
if (self::$runCounter % $manualGcInterval === 0) {
95+
if (self::$manualGcInterval > 0) {
96+
if (self::$runCounter % self::$manualGcInterval === 0) {
9697
gc_collect_cycles();
9798
}
9899

0 commit comments

Comments
 (0)