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 ownalloc and free callbacks.
PFMemSetFunctions must be called before PFInitialize. It can’t be called again after hooks have been set.
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
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.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
nullptr.
Android
On Android, pass an HCInitArgs struct containing the Java VM and application context: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.
