# Mini-Program Operation Mechanism
Depending on the Host-App environment in which the Mini-Program runs, the Mini-Program will have different startup mechanisms.
# 1. Mini-Program Startup
There are two scenarios for Mini-Program startup: Cold Start and Hot Start.
- Cold Start: Occurs when a user opens the Mini-Program for the first time or when the Mini-Program is reopened after being actively destroyed by the Host-App. In this case, the Mini-Program needs to be reloaded and restarted, which is a cold start.
- Hot Start: If a user has previously opened a Mini-Program and reopens it within a certain period, the Mini-Program does not need to restart. Instead, it is simply brought from the background to the foreground. This process is a hot start.
# 2. Foreground and Background States
After a Mini-Program starts, its interface is directly visible to the user, meaning the Mini-Program is in the foreground state.
When the user closes the Mini-Program by clicking the Capsule Button in the upper right corner or leaves the Host-App by pressing the Device Home Button, the Mini-Program is not immediately destroyed. Instead, it enters the background state. When the user reopens the client or the Mini-Program again, the Mini-Program transitions from the background back to the foreground.
# 3. Mini-Program Destruction Mechanism
# 3.1 Mobile
Typically, a Mini-Program is destroyed only after it has been in the background for a certain period or when it consumes excessive system resources. The destruction mechanism for mobile Mini-Programs is as follows:
- If a Mini-Program consumes excessive system resources, it may be destroyed by the system or actively reclaimed by the client.
- On iOS, a maximum of 5 Mini-Programs are allowed to exist simultaneously. If this limit is exceeded, the least recently used Mini-Program is destroyed. Additionally, when the client receives a memory warning, it actively destroys all background Mini-Programs.
- On Android, a maximum of 5 Mini-Programs are allowed to exist simultaneously. If this limit is exceeded, the least recently used Mini-Program is destroyed. Furthermore, when memory is low, the system directly reclaims memory, destroying Mini-Programs that have been inactive in the background for an extended period.
# 3.2 Desktop
On desktop platforms, as long as the Mini-Program is not closed, it remains running. If it is closed, it is destroyed immediately.
# 4. Mini-Program Opening Logic
The page opening logic for a Cold Start is straightforward, whereas a Hot Start is more complex because it may automatically trigger certain navigations.
Depending on the startup parameters, these navigations can be summarized as follows:
| Different Specified Page or Parameters | Effect |
|---|---|
| Yes | Clears the original page stack and opens the specified page |
| No | Retains the previous state |