Archived

This forum has been archived. Please start a new discussion on GitHub.

About garbage collector

I need to use the data which i get from ICE,but i want Keep it until i finish the job,but garbage collector will delete it when the flow finish.
Or maybe ican shut garbage collector down.
can you help me? TKS.

Comments

  • matthew
    matthew NL, Canada
    If you hold a reference the GC will not trash the data. If this is not occurring then there is some problem... If you think you've found a bug the simplest method is to send us a self-contained, compilable example based on the latest version of Ice which demonstrates the problem.
  • sorry about my describe.

    No,It's not bug.
    for example:
    client use callback send msg to server and receive some info in class CallbackReceiverI : public CallbackReceiver{}, when CallbackReceiverI finsih, the data will be delete by ICE,i guess it's garbage collector ,but i don't want put my deal fuction in the class CallbackReceiverI : public CallbackReceiver{}, i want to keep them in memery until i delete it.

    of course, i can copy it in class CallbackReceiverI : public CallbackReceiver{}, but it's too slow,so i want keep the primary data as well.

    TKS.
  • matthew
    matthew NL, Canada
    Sorry, its still not clear what you are doing. Could you give a concrete example?
  • soff.dong wrote: »
    No,It's not bug.
    for example:
    client use callback send msg to server and receive some info in class CallbackReceiverI : public CallbackReceiver{}, when CallbackReceiverI finsih, the data will be delete by ICE,i guess it's garbage collector ,but i don't want put my deal fuction in the class CallbackReceiverI : public CallbackReceiver{}, i want to keep them in memery until i delete it.

    The GC is disabled by default. So, unless you've turned it on explicitly, by setting Ice.GC.Interval or by explicitly calling Ice::collectGarbage, there will be no garbage collection. The one exception to this rule is that, when you destroy a communicator, the Ice run time makes a collection pass to reclaim the memory for any abandoned class cycles.

    Also, the only class instances that the collector deals with are those that are part of a cycle. Any class instance that is not part of a cycle is reclaimed when its reference count drops to zero, that is, when the last smart pointer to the instance goes out of scope.

    The garbage collector guarantees that it will collect only instances that are no longer reachable by any smart pointer in your program. If you have an instance you would like to hang onto, the reason almost certainly is that you are not keeping a smart pointer for the instance in scope that would keep it's reference count non-zero. This has nothing to do with the collector--it is simply a matter of how you use smart pointers.

    Do not keep C++ pointers or references to a class instance in your program. If you do, they will point into outer space once the last smart pointer to the instance goes out of scope.
    of course, i can copy it in class CallbackReceiverI : public CallbackReceiver{}, but it's too slow,so i want keep the primary data as well.

    There is usually no need to copy the class instance if you want to keep it around. Instead, you can keep a smart pointer to the instance. Assignment of the smart pointer has essentially zero cost and is much cheaper than instantiating and copying the instance itself.

    I suggest that you have a look at the "Smart Pointers for Classes" section in the Chapter 6 of the Ice Manual.

    If the issue you are seeing is indeed caused by the garbage collector, we'll need a code example that demonstrates the problem.

    Cheers,

    Michi.
  • I Get It ! Thank You , Both Of You!!