473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Garbage collection and Threads.

Hello,

I have an object that at some point creates a thread to run one of its
method.

I create that object within an application and after a while I set its
reference to null to let the gc reclaim it. now the problem is that I want
this thread to stop after the object is being deleted but this object sits
around because its main thread and the one it creates reference each other
even though me, from my application I have not reference of those objects.
Now calling dispose it's not an option because those object get created via
a COM and I can't change that to call an Unload method or whatever.

Any ideas ?

Thanks everyone.
Nov 16 '05 #1
2 1229
You say that the main thread and the worker thread reference each other,
but you also say that you release the references? Only one of those
statements can be true. Either you have a reference to it or you don't?

However, this doesn't mean that the thread stops running.

Is it a COM object that is creating the thread? If so, why do you want
to stop it? The COM object should be responsible for terminating the thread
gracefully, especially if you have released it.

If your object has a thread, and you have implemented IDispose on it,
then you should stop the thread when the Dispose method is called. If you
don't have an implementation of IDispose on this method, then you should.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"MaSTeR" <so***@nospam.com> wrote in message
news:32*************@individual.net...
Hello,

I have an object that at some point creates a thread to run one of its
method.

I create that object within an application and after a while I set its
reference to null to let the gc reclaim it. now the problem is that I want
this thread to stop after the object is being deleted but this object sits
around because its main thread and the one it creates reference each other
even though me, from my application I have not reference of those objects.
Now calling dispose it's not an option because those object get created
via
a COM and I can't change that to call an Unload method or whatever.

Any ideas ?

Thanks everyone.

Nov 16 '05 #2
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2*****************@TK2MSFTNGP09.phx.gbl...
You say that the main thread and the worker thread reference each other, but you also say that you release the references? Only one of those
statements can be true. Either you have a reference to it or you don't?
Sorry but again both statements are true. I have an object creating the
other object (so my first object has a reference to it). The second object
creates a thread that by default has a reference to the main thread (new
Thread(new StartThread(this.method)).

Now my first object sets to null the reference to the second object that
will never be garbage collected because it has a thread running. In C++ the
main object (the COM object) would have called Release-> (as it does now,
I've made my .Net object a com object) and this would have called the
destructor where you could handle thread signaling. With .Net objects this
doesn't happen.
However, this doesn't mean that the thread stops running.
Exactly.
Is it a COM object that is creating the thread? If so, why do you want to stop it? The COM object should be responsible for terminating the thread gracefully, especially if you have released it.
The com object is only responsible of calling Release on the COM object it
creates, doesn't matter if they're C++, VB or .Net.
If your object has a thread, and you have implemented IDispose on it,
then you should stop the thread when the Dispose method is called. If you
don't have an implementation of IDispose on this method, then you should.
As I said adding a method call from the main com object on termination is
not an option.
Hope this helps.

thanks for your help !
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Oculus | last post by:
Before I get into the question -- I know .NET isn't the right solution for this app but it's part of my clients requirements and writing this in C++ isn't an option. That being said -- my app is a...
14
by: Arvind | last post by:
hello ppl, i am trying to implement a garbage collector for c++ using the generational algorithm applying mark-sweep to each generation. i am unable to get any details about the algorithm. is it...
6
by: NutJob | last post by:
Hello all, I'm aware that in Python an object is cleared for garbage collection as soon as the last reference to it disappears. Normally this is fine. However, in my current project I'm creating...
8
by: Martin Maat | last post by:
I am puzzled. I have this object that uses a thread. The thread is encapsulated by the object, the object has Start and Stop methods to enable the client to start or stop the thread. I found...
5
by: Sunny | last post by:
Hi all, Does any one knows, if I create a thread in a method and start some processing in it, what happens when this thread object goes out of scope. Is it garbage collected (I assume yes, as it...
18
by: Larry Herbinaux | last post by:
I'm having issues with garbage collection with my long-standing service process. If you could review and point me in the right direction it would be of great help. If there are any helpful...
13
by: Mingnan G. | last post by:
Hello everyone. I have written a garbage collector for standard C++ application. It has following main features. 1) Deterministic Finalization Providing deterministic finalization, the system...
28
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will...
0
by: adubra | last post by:
Hi there, I am using a device context (DC) and a buffer to successfully draw to screen. However, when I update the DC at very high frame rate and drag the frame containing the image very quickly...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.