473,779 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reference Counting

MP
Hello everyone,
I am an old C++/COM programmer that converted about 8 months ago to
C#/.Net, and I have no regrets.

I am now converting our caching subsystem from COM to .Net and I have a
little problem to resolve. Our old COM cache would cleanup "unreferenc ed"
entities by checking the refcount on the entities in the cache. Whenever the
refcount was equal to 2 (this means the cache had a reference and the
cleanup had another) then we knew the entity was not referenced by the
application and it would get "destroyed" .

I undestand that .Net does not use refcounting, but I am confused as to
how I could cleanup in .Net. Can someone point me in the rigth direction?

Thank you!

-MP.
Nov 16 '05 #1
7 6503
Hi,
I think you should take a look at this article:
http://msdn.microsoft.com/msdnmag/is...i/default.aspx

I hope this helps.

- Alexander Rauser

http://www.flashshop.info

MP wrote:
Hello everyone,
I am an old C++/COM programmer that converted about 8 months ago to
C#/.Net, and I have no regrets.

I am now converting our caching subsystem from COM to .Net and I have a
little problem to resolve. Our old COM cache would cleanup "unreferenc ed"
entities by checking the refcount on the entities in the cache. Whenever the
refcount was equal to 2 (this means the cache had a reference and the
cleanup had another) then we knew the entity was not referenced by the
application and it would get "destroyed" .

I undestand that .Net does not use refcounting, but I am confused as to
how I could cleanup in .Net. Can someone point me in the rigth direction?

Thank you!

-MP.

Nov 16 '05 #2
MP
Thank you Alex, I will.

-MP
"Alex" <www.flashshop. info> wrote in message
news:eK******** ******@TK2MSFTN GP10.phx.gbl...
Hi,
I think you should take a look at this article:
http://msdn.microsoft.com/msdnmag/is...i/default.aspx

I hope this helps.

- Alexander Rauser

http://www.flashshop.info

MP wrote:
Hello everyone,
I am an old C++/COM programmer that converted about 8 months ago to
C#/.Net, and I have no regrets.

I am now converting our caching subsystem from COM to .Net and I have
a little problem to resolve. Our old COM cache would cleanup
"unreferenc ed" entities by checking the refcount on the entities in the
cache. Whenever the refcount was equal to 2 (this means the cache had a
reference and the cleanup had another) then we knew the entity was not
referenced by the application and it would get "destroyed" .

I undestand that .Net does not use refcounting, but I am confused as
to how I could cleanup in .Net. Can someone point me in the rigth
direction?

Thank you!

-MP.

Nov 16 '05 #3
In addition to Alex's response, if you're going to be implementing your own
caching system, have a look at the MSDN documentation for WeakReference.
This allows you to hold references to items that can still be garbage
collected, assuming no strong references to them exist. It has an IsAlive
property to allow you to check if the object is still in memory. It's
theoretically similar to having a COM pointer to an object without calling
AddRef(). Since a garbage collection might only collect the object some time
after all strong references to it are cleared, holding onto the weak
reference acts as quite a nice caching mechanism.

Of course, you'd probably be better off using an existing caching system
(such as the Caching Application Block).

"MP" <martin.pare@I_ Will_Not_Give_Y ou_My_Address> wrote in message
news:OD******** *****@TK2MSFTNG P14.phx.gbl...
Hello everyone,
I am an old C++/COM programmer that converted about 8 months ago to
C#/.Net, and I have no regrets.

I am now converting our caching subsystem from COM to .Net and I have a
little problem to resolve. Our old COM cache would cleanup "unreferenc ed"
entities by checking the refcount on the entities in the cache. Whenever
the refcount was equal to 2 (this means the cache had a reference and the
cleanup had another) then we knew the entity was not referenced by the
application and it would get "destroyed" .

I undestand that .Net does not use refcounting, but I am confused as to
how I could cleanup in .Net. Can someone point me in the rigth direction?

Thank you!

-MP.

Nov 16 '05 #4
CRL manages reference counting automatically. To make it call Release() all
you need is to assign null to the COM object reference. It will mark the
object for garbage collction. There is another possibility of calling
Release() explicitly from the code like this:

using System.Runtime. InteropServices ;

IntPtr intptr = Marshal.GetIUnk nownForObject(c omObject);
int count = Marshal.Release (intptr);


"Sean Hederman" wrote:
In addition to Alex's response, if you're going to be implementing your own
caching system, have a look at the MSDN documentation for WeakReference.
This allows you to hold references to items that can still be garbage
collected, assuming no strong references to them exist. It has an IsAlive
property to allow you to check if the object is still in memory. It's
theoretically similar to having a COM pointer to an object without calling
AddRef(). Since a garbage collection might only collect the object some time
after all strong references to it are cleared, holding onto the weak
reference acts as quite a nice caching mechanism.

Of course, you'd probably be better off using an existing caching system
(such as the Caching Application Block).

"MP" <martin.pare@I_ Will_Not_Give_Y ou_My_Address> wrote in message
news:OD******** *****@TK2MSFTNG P14.phx.gbl...
Hello everyone,
I am an old C++/COM programmer that converted about 8 months ago to
C#/.Net, and I have no regrets.

I am now converting our caching subsystem from COM to .Net and I have a
little problem to resolve. Our old COM cache would cleanup "unreferenc ed"
entities by checking the refcount on the entities in the cache. Whenever
the refcount was equal to 2 (this means the cache had a reference and the
cleanup had another) then we knew the entity was not referenced by the
application and it would get "destroyed" .

I undestand that .Net does not use refcounting, but I am confused as to
how I could cleanup in .Net. Can someone point me in the rigth direction?

Thank you!

-MP.


Nov 16 '05 #5
MP
Thank you Shaun,
I will look at this as well, seems like the ideal solution.

About the Caching Application Block, do you have some experience with it?
I will read about it.

Thank you !

-MP

"Sean Hederman" <us***@blogentr y.com> wrote in message
news:cu******** **@ctb-nnrp2.saix.net. ..
In addition to Alex's response, if you're going to be implementing your
own caching system, have a look at the MSDN documentation for
WeakReference. This allows you to hold references to items that can still
be garbage collected, assuming no strong references to them exist. It has
an IsAlive property to allow you to check if the object is still in
memory. It's theoretically similar to having a COM pointer to an object
without calling AddRef(). Since a garbage collection might only collect
the object some time after all strong references to it are cleared,
holding onto the weak reference acts as quite a nice caching mechanism.

Of course, you'd probably be better off using an existing caching system
(such as the Caching Application Block).

"MP" <martin.pare@I_ Will_Not_Give_Y ou_My_Address> wrote in message
news:OD******** *****@TK2MSFTNG P14.phx.gbl...
Hello everyone,
I am an old C++/COM programmer that converted about 8 months ago to
C#/.Net, and I have no regrets.

I am now converting our caching subsystem from COM to .Net and I have
a little problem to resolve. Our old COM cache would cleanup
"unreferenc ed" entities by checking the refcount on the entities in the
cache. Whenever the refcount was equal to 2 (this means the cache had a
reference and the cleanup had another) then we knew the entity was not
referenced by the application and it would get "destroyed" .

I undestand that .Net does not use refcounting, but I am confused as
to how I could cleanup in .Net. Can someone point me in the rigth
direction?

Thank you!

-MP.


Nov 16 '05 #6
Microsoft just released their new enterprise blocks. This is re-working (I
believe) of the current blocks.

http://msdn.microsoft.com/library/de...tml/entlib.asp

Current blocks had lots of dependencies and were implemented differently
across the blocks, the new enterprise blocks are suppose to give the blocks
a more consistent feel across blocks. Also some of the dependencies were
removed (again I believe this to be true)

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

"MP" <martin.pare@I_ Will_Not_Give_Y ou_My_Address> wrote in message
news:uz******** ******@TK2MSFTN GP14.phx.gbl...
Thank you Shaun,
I will look at this as well, seems like the ideal solution.

About the Caching Application Block, do you have some experience with it? I will read about it.

Thank you !

-MP

"Sean Hederman" <us***@blogentr y.com> wrote in message
news:cu******** **@ctb-nnrp2.saix.net. ..
In addition to Alex's response, if you're going to be implementing your
own caching system, have a look at the MSDN documentation for
WeakReference. This allows you to hold references to items that can still be garbage collected, assuming no strong references to them exist. It has an IsAlive property to allow you to check if the object is still in
memory. It's theoretically similar to having a COM pointer to an object
without calling AddRef(). Since a garbage collection might only collect
the object some time after all strong references to it are cleared,
holding onto the weak reference acts as quite a nice caching mechanism.

Of course, you'd probably be better off using an existing caching system
(such as the Caching Application Block).

"MP" <martin.pare@I_ Will_Not_Give_Y ou_My_Address> wrote in message
news:OD******** *****@TK2MSFTNG P14.phx.gbl...
Hello everyone,
I am an old C++/COM programmer that converted about 8 months ago to
C#/.Net, and I have no regrets.

I am now converting our caching subsystem from COM to .Net and I have a little problem to resolve. Our old COM cache would cleanup
"unreferenc ed" entities by checking the refcount on the entities in the
cache. Whenever the refcount was equal to 2 (this means the cache had a
reference and the cleanup had another) then we knew the entity was not
referenced by the application and it would get "destroyed" .

I undestand that .Net does not use refcounting, but I am confused as
to how I could cleanup in .Net. Can someone point me in the rigth
direction?

Thank you!

-MP.



Nov 16 '05 #7
MP
Thank you Wayne. I'll have a look at it.

Have a nice day!
"Wayne" <Me******@commu nity.nospam> wrote in message
news:ef******** ********@TK2MSF TNGP09.phx.gbl. ..
Microsoft just released their new enterprise blocks. This is re-working (I
believe) of the current blocks.

http://msdn.microsoft.com/library/de...tml/entlib.asp

Current blocks had lots of dependencies and were implemented differently
across the blocks, the new enterprise blocks are suppose to give the
blocks
a more consistent feel across blocks. Also some of the dependencies were
removed (again I believe this to be true)

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute.
But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

"MP" <martin.pare@I_ Will_Not_Give_Y ou_My_Address> wrote in message
news:uz******** ******@TK2MSFTN GP14.phx.gbl...
Thank you Shaun,
I will look at this as well, seems like the ideal solution.

About the Caching Application Block, do you have some experience with

it?
I will read about it.

Thank you !

-MP

"Sean Hederman" <us***@blogentr y.com> wrote in message
news:cu******** **@ctb-nnrp2.saix.net. ..
> In addition to Alex's response, if you're going to be implementing your
> own caching system, have a look at the MSDN documentation for
> WeakReference. This allows you to hold references to items that can still > be garbage collected, assuming no strong references to them exist. It has > an IsAlive property to allow you to check if the object is still in
> memory. It's theoretically similar to having a COM pointer to an object
> without calling AddRef(). Since a garbage collection might only collect
> the object some time after all strong references to it are cleared,
> holding onto the weak reference acts as quite a nice caching mechanism.
>
> Of course, you'd probably be better off using an existing caching
> system
> (such as the Caching Application Block).
>
> "MP" <martin.pare@I_ Will_Not_Give_Y ou_My_Address> wrote in message
> news:OD******** *****@TK2MSFTNG P14.phx.gbl...
>> Hello everyone,
>> I am an old C++/COM programmer that converted about 8 months ago to
>> C#/.Net, and I have no regrets.
>>
>> I am now converting our caching subsystem from COM to .Net and I have >> a little problem to resolve. Our old COM cache would cleanup
>> "unreferenc ed" entities by checking the refcount on the entities in
>> the
>> cache. Whenever the refcount was equal to 2 (this means the cache had
>> a
>> reference and the cleanup had another) then we knew the entity was not
>> referenced by the application and it would get "destroyed" .
>>
>> I undestand that .Net does not use refcounting, but I am confused
>> as
>> to how I could cleanup in .Net. Can someone point me in the rigth
>> direction?
>>
>> Thank you!
>>
>> -MP.
>>
>
>



Nov 16 '05 #8

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

Similar topics

6
2185
by: Elbert Lev | last post by:
Please correct me if I'm wrong. Python (as I understand) uses reference counting to determine when to delete the object. As soon as the object goes out of the scope it is deleted. Python does not use garbage collection (as Java does). So if the script runs a loop: for i in range(100): f = Obj(i)
1
2711
by: ash | last post by:
hi does anyone has any experience with flyweight pattern with refernce counting i want to share objects between multiple clients and want to delete the object from shared pool when the last client deletes a refernce to it
27
5974
by: Jason Heyes | last post by:
To my understanding, std::vector does not use reference counting to avoid the overhead of copying and initialisation. Where can I get a reference counted implementation of std::vector? Thanks.
0
1754
by: Kalle Rutanen | last post by:
Hello I implemented reference counting in my program, and found out many problems associated with it. I wonder if the following problems can be solved automatically rather manually ? 1. In its member function, an object manages to destroy last reference to itself and thus destructs before the end of the member function.
1
3253
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage collector, such as the one used in Java, maintains a record of whether or not an object is currentlys being used. An unused object is tagged as garbage,
1
1877
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage collector, such as the one used in Java, maintains a record of whether or not an object is currentlys being used. An unused object is tagged as garbage,
4
4198
by: aaronfude | last post by:
Hi, Please consider the following class (it's not really my class, but it's a good example for my question): class Vector { int myN; double *myX; Vector(int n) : myN(n), myX(new double) { } double &operator()(int i) { return myX; }
1
2278
by: oec.deepak | last post by:
Hi Cn any one telll me what is Reference counting in C++.
8
1862
by: mathieu | last post by:
Hi there I have implemented a very simple smartpointer class (invasive design). And I was wondering what should be the natural API when using those in a Container. I choose to define the following operator in my smartpointer class: .... operator ObjectType * () const
275
12400
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10302
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.