question

Xynan Lee avatar image
Xynan Lee asked

Does ExecuteCloudScript bindings cause memory leaks?

Hi, I'm currently playing around with Playfab in Unreal Engine. I have come across the tutorial in executing Cloud Script with this function.

bool UPlayFabClientAPI::ExecuteCloudScript(
    ClientModels::FExecuteCloudScriptRequest& request,
    const FExecuteCloudScriptDelegate& SuccessDelegate,
    const FPlayFabErrorDelegate& ErrorDelegate){}

This function is the callback of the execution.

void UPlayFabClientAPI::OnExecuteCloudScriptResult(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FExecuteCloudScriptDelegate SuccessDelegate, FPlayFabErrorDelegate ErrorDelegate)
{
    ClientModels::FExecuteCloudScriptResult outResult;
    FPlayFabCppError errorResult;
    if (PlayFabRequestHandler::DecodeRequest(HttpRequest, HttpResponse, bSucceeded, outResult, errorResult))
    {
        SuccessDelegate.ExecuteIfBound(outResult);
    }
    else
    {
        ErrorDelegate.ExecuteIfBound(errorResult);
    }
}

The part that worries me is both SuccessDelegate and ErrorDelegate are left unbound.

If I have to call execute the CloudScript frequently, will the bindings for SuccessDelegate and ErrorDelegate cause memory leaks due to reoccurring bindings?

My current methods of executing CloudScripts are

ClientAPI->ExecuteCloudScript(CSRequest, 
	PlayFab::UPlayFabClientAPI::FExecuteCloudScriptDelegate::CreateUObject(this, &USTGameInstance::OnExecuteSucess),
	PlayFab::FPlayFabErrorDelegate::CreateUObject(this, &USTGameInstance::OnExecuteFailed));

and

ClientAPI->ExecuteCloudScript(CSRequest,
    PlayFab::UPlayFabClientAPI::FExecuteCloudScriptDelegate::CreateLambda([](const PlayFab::ClientModels::FExecuteCloudScriptResult& Result)-> void
    {
        ///// Lambda code for success
    }),
    PlayFab::FPlayFabErrorDelegate::CreateLambda([](const PlayFab::FPlayFabCppError& ErrorResult)-> void
    {
        ///// Lambda code for failure
    }));

CloudScriptunreal
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Hi @Xynan Lee,

>>If I have to call execute the CloudScript frequently, will the bindings for SuccessDelegate and ErrorDelegate cause memory leaks due to reoccurring bindings?

According to this UE4 doc, ExecuteIfBound() will first check whether the delegate is bound, if it’s unbound, it won’t be executed. And UE4 provides garbage collecting mechanism, inactive memory will be recycled, hence memory leak shall not happen.

If you can find the evidence of memory leak issue, please provide the reproduce steps and samples for investigation, thanks:)

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.