OmniThreadLibrary forum
News: SMF - Just Installed!
 
*
Welcome, Guest. Please login or register. February 08, 2012, 06:33:27 AM


Login with username, password and session length


Pages: [1]   Go Down
  Print  
Author Topic: When to destroy object created in thread, and passed to main thread in message?  (Read 666 times)
Vegar
Newbie
*
Posts: 23


View Profile
« on: August 31, 2010, 08:17:03 AM »

Hi,

In my worker, I do a soap request, resulting in a newly created object holding data return from the request. This data is passed in a message to the main thread, which updates the gui with the data.

In the workers cleanup-method, I free the created object.

This results in a exception, cause the main thread has not always processed the message before the workers cleanup method gets called.

So where should I do the cleanup? Should I let the main thread destroy the object, or can I do anything to ensure that messages is processed before cleanup is called?

regards,
-Vegar
Logged
Primoz Gabrijelcic
Administrator
Hero Member
*****
Posts: 520


View Profile Email
« Reply #1 on: August 31, 2010, 11:47:17 AM »

Free the object in the main thread. I do it all the time.

Passing ownership together with the data is useful semantics. You just have to keep in mind that you're doing it.
Logged
bendeguzz
Newbie
*
Posts: 8


View Profile
« Reply #2 on: September 06, 2010, 10:00:37 AM »

I needed something similar, and what I did was that I wrote a 'CleanUp()' procedure, which was called via a message from the main thread, after I've done everything I needed with the object.

PS: my object had a 'Processed' boolean field, which marked if it is freeable.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM