Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak in Thread Pool factory when exception raised #88

Closed
jsmart73 opened this issue Jan 17, 2017 · 2 comments
Closed

Memory Leak in Thread Pool factory when exception raised #88

jsmart73 opened this issue Jan 17, 2017 · 2 comments

Comments

@jsmart73
Copy link

See example code:

program Project2;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  otlTaskControl,
  otlTask,
  otlThreadPool;

var
  Pool: IOmniThreadPool;

function AFactory: IInterface;
begin
  raise Exception.Create('Error Message');
end;

begin
  try
    ReportMemoryLeaksOnShutdown := True;

    Pool := CreateThreadPool('Test');
    Pool.SetThreadDataFactory(AFactory);

    CreateTask(procedure (const task: IOmnitask) begin end).Schedule(Pool);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Results in memory leak - TBits, TOmniIntegerSet and TOTPWorkItem, TOmniTask (run above in console to see details)

@gabr42
Copy link
Owner

gabr42 commented Jan 17, 2017

I agree that is not the best solution. The real question, however, is - what to do if a factory throws an exception? There is probably a no clean way to continue execution.

@jsmart73
Copy link
Author

No, you're right. There is no clean way.
For me, if possible and not having thought too much about it, could we just clean up the objects that are cleaning and execute the OnTerminate event (if there is one)?

gabr42 added a commit that referenced this issue Feb 3, 2017
If ThreadDataFactory.Execute throws an exception, that exception is
caught, ignored and ThreadData is set to nil.

closes issue #88
@gabr42 gabr42 closed this as completed Feb 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants