Skip to main content
This page covers the complete startup and shutdown sequence for the PlayFab Services SDK. Every title follows the same high-level pattern: configure optional hooks, initialize Core, create a service configuration, initialize Services, do work, then shut down in reverse order.

Initialization sequence

Initialization has four steps. The first is optional; the remaining three are required.

Step 1: Set custom memory hooks (optional)

If your title uses a custom memory allocator, call PFMemSetFunctions before any other PlayFab API. This routes all SDK memory allocations through your own alloc and free callbacks.
PFMemSetFunctions must be called before PFInitialize. It can’t be called again after hooks have been set.
If you don’t need custom memory management, skip this step. The SDK uses default allocation routines.

Step 2: Initialize PlayFab Core

PFInitialize sets up the SDK’s global state, including the HTTP layer and background task queue. The exact signature varies by platform.

Windows, Linux, iOS, and macOS

Pass an XTaskQueueHandle if you want to control which queue handles background work. Pass nullptr to use the default threadpool queue.

Android

On Android, you must also provide the Java VM and application context so the SDK can initialize libHttpClient:
If you don’t call PFInitialize explicitly, PFServicesInitialize calls it internally with default parameters. This is fine for most titles. However, if you’re using custom memory hooks via PFMemSetFunctions, you must call PFInitialize yourself — otherwise PFServicesInitialize initializes Core before your memory hooks take effect, and the SDK uses default allocation routines instead.

Step 3: Create a service configuration

PFServiceConfigCreateHandle creates a handle that tells the SDK which PlayFab title and endpoint to target. You’ll find both values in Game Manager.
The returned PFServiceConfigHandle is required for all subsequent login calls.

Step 4: Initialize PlayFab Services

PFServicesInitialize sets up the Services layer (Inventory, Leaderboards, Friends, and so on) on top of Core.

Windows, Linux, iOS, and macOS

The parameter is reserved for future use; pass nullptr.

Android

On Android, pass an HCInitArgs struct containing the Java VM and application context:
After this call succeeds, the SDK is ready. You can log in players and make service calls.

PFServiceConfigHandle lifecycle

A PFServiceConfigHandle is a ref-counted handle. The SDK manages its internal lifetime through reference counting, but you’re responsible for closing every handle you own.

Duplicating a handle

Use PFServiceConfigDuplicateHandle when you need to share a service config across components that manage their own lifetimes:

Shutdown sequence

Shutdown is the reverse of initialization. You must uninitialize Services before Core, and both calls are asynchronous.

Step 1: Close all open handles

Before tearing down the SDK, close every PFEntityHandle and PFServiceConfigHandle you own:

Step 2: Uninitialize Services

PFServicesUninitializeAsync tears down the Services layer. Wait for it to complete before proceeding.

Step 3: Uninitialize Core

After Services cleanup finishes, call PFUninitializeAsync to tear down Core:
If you didn’t call PFInitialize explicitly, you can skip PFUninitializeAsync. In that case, PFServicesUninitializeAsync handles Core cleanup automatically. However, if you did call PFInitialize yourself, you must call PFUninitializeAsync yourself.

Complete example

This example shows the full lifecycle from initialization through shutdown on a Windows title:

Common mistakes

See also

Last modified on August 10, 2026