Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 02-27-2008
zzm7000 zzm7000 is offline
Registered User
 
Name: Zhao Ziming
Organization: Beijing University of Posts and Telecommunications
Project: End to end security
 
Join Date: Feb 2008
Location: Beijing
Posts: 2
Arrow Release "callback class" in AMI

Hello, guys:
i am developing a service requiring AMI. However i'v got a problem. The following is a example slice definition.

module Demo
{
interface Server
{
["ami"] int Process(int iReqLen)
};
};

//The following is from the client side
try
{
char ProxyString[100];
sprintf(ProxyString, "Server:tcp -h %s -p %d", g_ServerIp, g_ServerPort);

Ice::ObjectPrx pBase = g_IcePtr->stringToProxy(ProxyString);
ServerPrx Transer = ServerPrx::checkedCast(pBase);
if (!Transer)
{...}

Transer->Process_async(new AMI_Server_ProcessI, iReqLen);//PROBLEM HERE
}
My problem is:
will this code lead to a memory leakage? the new AMI_Server_ProcessI is never destroyed? i see AMI_Server_ProcessI is derived from "class shared" which has a member "__ref". So i assume that when "new AMI_Server_ProcessI" is called the __ref will be increased.
i tried to call "_decRef()" in the AMI_KMCServer_ProcessI::ice_response(), however i got a fatal error in run-time.
if i use the following codes:
AMI_KMCServer_ProcessPtr p = new AMI_KMCServer_ProcessI;
Transer->Process_async(p, iReqLen);
when p's life ends, it will release the "AMI_KMCServer_ProcessI", right? because p is an auto variable, this will lead to problems that "AMI_KMCServer_ProcessI" is released before "ice_response" get called. how can i fix this?
thank u.
Reply With Quote
  #2 (permalink)  
Old 02-28-2008
matthew's Avatar
matthew matthew is offline
ZeroC Staff
 
Name: Matthew Newhook
Organization: ZeroC, Inc.
Project: Internet Communications Engine
 
Join Date: Feb 2003
Location: NL, Canada
Posts: 1,061
The code samples as presented above will not leak. I recommend you read section 6.14.6 "Smart Pointers for Classes" in the Ice manual for a detailed explanation. If you have more questions after reviewing this please let me know!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008
zzm7000 zzm7000 is offline
Registered User
 
Name: Zhao Ziming
Organization: Beijing University of Posts and Telecommunications
Project: End to end security
 
Join Date: Feb 2008
Location: Beijing
Posts: 2
Thank you, Matthew:
After reading section 6.14.6 in the manual, and after a careful debug, i think i have figure out what is actually going on in the code.

Transer->Process_async(new AMI_Server_ProcessI, iReqLen);

first, after a AMI_Server_ProcessI instance is created and passed to function "Process_async", the constructor of IceUtil::Handle<AMI_Server_ProcessI> is called. And __incRef is called in this constructor.
Second, which is the point i didnot think through earlier, is that function "Process_async" will also call __incRef. So when the stack variable IceUtil::Handle<AMI_Server_ProcessI> goes out od scope, __ref in AMI_Server_ProcessI is still not zero.
Third, i assume that after ice_response() is called ice-runtime will also call __decRef(). This also explain why i get a fatal error when i add __defRef() explicitly in my ice_response().
Am i right? I wish i have time to study the ice source thoroughly. Thank you very much.
Reply With Quote
  #4 (permalink)  
Old 02-28-2008
matthew's Avatar
matthew matthew is offline
ZeroC Staff
 
Name: Matthew Newhook
Organization: ZeroC, Inc.
Project: Internet Communications Engine
 
Join Date: Feb 2003
Location: NL, Canada
Posts: 1,061
Yes, your analysis is correct!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Don't "Ice-3.1.1-VC71.msi " include the "slice2java.exe"? Jason Gao Help Center 4 10-26-2006 12:23 PM
"make test" failure on Ice 3.0.1 installation. SUSE 10.1. pchapin Help Center 4 05-22-2006 11:20 PM
The "callback" string in the callback demo catalin Help Center 2 08-27-2004 01:53 AM
Going from "in" to "out" param, using a class as a union catalin Help Center 1 04-05-2004 09:55 AM
Ice-1.1.0: compile error "undefined reference to xercesc_2_2" Urs Help Center 2 05-30-2003 04:29 PM


All times are GMT -4. The time now is 01:46 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.