AddRef and Release

This is a discussion on AddRef and Release within the C++ Programming forums, part of the General Programming Boards category; They go away when the reference count is 0. That's the COM protocol. I just read the thread carefully and ...

  1. #16
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    They go away when the reference count is 0. That's the COM protocol.

    I just read the thread carefully and I'm still fuzzy what you were arguing. But it didn't have anything to do with George2's code.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    George2 were claiming that while a pointer is still pointing (read: has a reference) to the object, it won't go away.
    I was explaining the concept that you can have a thousand pointers pointing to the object, and the ref count can still be 1, and if it was, if you called Release then, the object would be destroyed regardless how many pointers were pointing to the object because the reference count would reach 0.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi Elysia,


    I am reading the book Inside COM. It mentioned when there is a new pointer, we should call AddRef, except that we optimize the performance and clear the nested relationship of pointers.

    Looks like your concept of reference count and pointer count are different. But in COM (at least in the book), reference count and pointer count are both the same. :-)

    Quote Originally Posted by Elysia View Post
    George2 were claiming that while a pointer is still pointing (read: has a reference) to the object, it won't go away.
    I was explaining the concept that you can have a thousand pointers pointing to the object, and the ref count can still be 1, and if it was, if you called Release then, the object would be destroyed regardless how many pointers were pointing to the object because the reference count would reach 0.

    regards,
    George

  4. #19
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    George2 were claiming that while a pointer is still pointing (read: has a reference) to the object, it won't go away.
    No, he wasn't. He got confused by your insistence that Release() should be called after assigning a new value to the pointer (and just how would you call Release() on the old one then?) and merged the idea of having a pointer to the interface and having called AddRef() on it (thus keeping the object alive even if all other holders call Release() to match their own AddRef()). He was, in other words, thinking as a COM programmer should.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #20
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    Anyway, the idea that when the reference count reaches 0, the object is destroyed is correct. And further, you shouldn't call either AddRef or Release; you should use CComPtr instead.
    No trouble with pesky reference count then.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks CornedBee,


    This is what I am thinking. :-)

    Quote Originally Posted by CornedBee View Post
    No, he wasn't. He got confused by your insistence that Release() should be called after assigning a new value to the pointer (and just how would you call Release() on the old one then?) and merged the idea of having a pointer to the interface and having called AddRef() on it (thus keeping the object alive even if all other holders call Release() to match their own AddRef()). He was, in other words, thinking as a COM programmer should.

    regards,
    George

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  2. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  3. AddRef and Release function of COM inteface
    By George2 in forum C++ Programming
    Replies: 0
    Last Post: 10-18-2007, 06:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21