Jump to content
Sign in to follow this  
Attila Kovacs

freeing an object in different process

Recommended Posts

is it ok regarding to multithread design pattern to free an object in a different process thread as it was created in?

 

Seems to work, but are there any caveats?

function TfrmSync.NewCookieList: TclCookieList;
begin
  Result := TclCookieList.Create(nil, TclCookieItem);
  Result.Assign(FCookies);
end;

mainthread
begin
  ...
  Fpipeline := Parallel.pipeline.Stage(Retriever, ....)...Run;
  Fpipeline.input.Add(TRetrieverParam.Create(..., NewCookieList));  <---- New instance
  ...
  Fpipeline.input.CompleteAdding;
end;

procedure TfrmSync.Retriever(const input: TOmniValue; var output: TOmniValue);
begin
.....
TRetrieverParam(input).CookieList.Free;   <---- EOL
end;

 

Edited by Attila Kovacs

Share this post


Link to post

No caveats for above code. You can freely Free object instance from different thread than one where it is created.  

 

Problem would arise if you would have object instance that is being simultaneously accessed by multiple threads.

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×