Skip to content

Conversation

andreichuk
Copy link

cancelling timeout CancellationToken in Ask in order to prevent memory leaks -- a reference to 'result' variable is stored in CancellationToken's callback which prevents it from garbage collection. it's a huge problem when your timeout value is more or less big and your actor returns big data:

 public sealed class LeakActor : ReceiveActor
 {
     public LeakActor()
     {
         Receive<GetDataMessage>(message => Sender.Tell(new byte[10000]));
     }

    public sealed class GetDataMessage { }
}

then call it somewhere:

for (var index = 0; index < 10000; index += 1)
{
    await greeter.Ask<byte[]>(new LeakActor.GetDataMessage(), TimeSpan.FromSeconds(10));
}

the next calls were rearranged because a future actor should set result before _unregister() cancels Token:

_result.TrySetResult(message);
_unregister();

…y leaks -- a reference to 'result' variable is stored in CancellationToken's callback which prevents it from garbage collection
@Aaronontheweb
Copy link
Member

@andreichuk great catch. Going to stage this for 1.1.1

@Aaronontheweb Aaronontheweb merged commit 6aaa0b9 into akkadotnet:dev Jul 7, 2016
@andreichuk andreichuk deleted the futures_ask_memory_leak branch July 7, 2016 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants