Skip to content

Commit

Permalink
Fixes #12 memory leak in ThreadPoolExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Sep 10, 2021
1 parent 4f2fa0e commit 9518520
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]


### Fixed
- [Issue #12](https://github.com/vegardit/haxe-concurrent/issues/12) memory leak in ThreadPoolExecutor


## [3.0.1] - 2021-08-01

### Fixed
Expand Down
11 changes: 9 additions & 2 deletions src/hx/concurrent/executor/ThreadPoolExecutor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ class ThreadPoolExecutor extends Executor {
/*
* purge done tasks from list
*/
if (doneTasks.length > 0)
if (doneTasks.length > 0) {
for (t in doneTasks)
_scheduledTasks.remove(t);

#if python @:nullSafety(Off) #end // null-safety false positive
doneTasks.resize(0);
}

/*
* process newly scheduled tasks or sleep
*/
Expand Down Expand Up @@ -123,7 +127,10 @@ class ThreadPoolExecutor extends Executor {
if (state != RUNNING)
throw 'Cannot accept new tasks. Executor is not in state [RUNNING] but [$state].';

final future = new TaskFutureImpl<T>(this, task, schedule == null ? Executor.NOW_ONCE : schedule);
if (schedule == null)
schedule = Executor.NOW_ONCE;

final future = new TaskFutureImpl<T>(this, task, schedule);

// skip round-trip via scheduler for one-shot tasks that should be executed immediately
switch(schedule) {
Expand Down

0 comments on commit 9518520

Please sign in to comment.