Home Help Center

About garbage collector

soff.dongsoff.dong Member qiao dongOrganization: accuradProject: v6's net project ✭✭
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

  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    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.
  • soff.dongsoff.dong Member qiao dongOrganization: accuradProject: v6's net project ✭✭
    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.
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    Sorry, its still not clear what you are doing. Could you give a concrete example?
  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    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.
  • soff.dongsoff.dong Member qiao dongOrganization: accuradProject: v6's net project ✭✭
    I Get It ! Thank You , Both Of You!!
Sign In or Register to comment.