Hi,

I'm trying to write an async grpc client and looking into greeter async 
example.

https://github.com/grpc/grpc/blob/master/examples/cpp/helloworld/greeter_async_client2.cc

In the SayHello function, it new an AsyncClientCall object and then pass 
the object  to the  Finish function.

// Assembles the client's payload and sends it to the server.
void SayHello(const std::string& user) {
    // Data we are sending to the server.
    HelloRequest request;
    request.set_name(user);

    // Call object to store rpc data
    AsyncClientCall* call = new AsyncClientCall;

    // stub_->PrepareAsyncSayHello() creates an RPC object, returning
    // an instance to store in "call" but does not actually start the RPC
    // Because we are using the asynchronous API, we need to hold on to
    // the "call" instance in order to get updates on the ongoing RPC.
    call->response_reader =
        stub_->PrepareAsyncSayHello(&call->context, request, &cq_);

    // StartCall initiates the RPC call
    call->response_reader->StartCall();

    // Request that, upon completion of the RPC, "reply" be updated with the
    // server's response; "status" with the indication of whether the 
operation
    // was successful. Tag the request with the memory address of the call 
object.
    call->response_reader->Finish(&call->reply, &call->status, (void*)call);

}

In the function AsyncCompleteRpc, it casts the object back to 
AsyncClientCall  and delete the object.

// Loop while listening for completed responses.
// Prints out the response from the server.
void AsyncCompleteRpc() {
    void* got_tag;
    bool ok = false;

    // Block until the next result is available in the completion queue 
"cq".
    while (cq_.Next(&got_tag, &ok)) {
        // The tag in this example is the memory location of the call object
        AsyncClientCall* call = static_cast<AsyncClientCall*>(got_tag);

        ...


        // Once we're complete, deallocate the call object.
        delete call;

So my question is, is there any possibility that function  AsyncCompleteRpc 
doesn't 
have chance to receive the message in cq_, which lead to memory leak?

I mean an object newed in the function SayHello, does it make sure to be 
received in function AsyncCompleteRpc,and delete the object?

Thanks a lot!

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/47119edf-78fe-4bce-84cb-47a1d9180d10%40googlegroups.com.

Reply via email to