-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added detach and unmount immediate to documentation
- Loading branch information
1 parent
bc7a30b
commit 14cf64b
Showing
3 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Unsafe Detach and Unload Immediate | ||
|
||
:::warning | ||
**It is not recommended to use this API unless you are an advanced user.** When using this API, you are responsible for managing the lifecycle of the Unity instance. If you are not careful, you may encounter memory leaks or other issues. | ||
::: | ||
|
||
The `UNSAFE__detachAndUnloadImmediate` function is used to detach and unload the Unity instance immediately. This function is useful when you want to unload the Unity instance immediately without waiting for the next garbage collection cycle. | ||
|
||
## Type Definition | ||
|
||
```ts title="Type Definition" | ||
const UNSAFE__detachAndUnloadImmediate: () => Promise<void>; | ||
``` | ||
|
||
## Example Usage | ||
|
||
A basic implementation could look something like this. In the following example we are using the `useEffect` hook to call the `UNSAFE__detachAndUnloadImmediate` function when the component is unmounted. | ||
|
||
```jsx {12-15} showLineNumbers title="App.jsx" | ||
import React, { useEffect } from "react"; | ||
import { Unity, useUnityContext } from "react-unity-webgl"; | ||
|
||
function App() { | ||
const { unityProvider, UNSAFE__detachAndUnloadImmediate } = useUnityContext({ | ||
loaderUrl: "build/myunityapp.loader.js", | ||
dataUrl: "build/myunityapp.data", | ||
frameworkUrl: "build/myunityapp.framework.js", | ||
codeUrl: "build/myunityapp.wasm", | ||
}); | ||
|
||
useEffect(() => { | ||
return () => { | ||
UNSAFE__detachAndUnloadImmediate(); | ||
}; | ||
}, []); | ||
|
||
return <Unity unityProvider={unityProvider} />; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters