> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/ably/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Lifecycle events

## Handle synchronization events

The channel.object instance emits synchronization events that indicate when the local state on the client is being synchronized with the Ably service. These events can be useful for displaying loading indicators, preventing user interactions during synchronization, or triggering application logic when data is first loaded.

| Event   | Description                                                                                      |
| ------- | ------------------------------------------------------------------------------------------------ |
| syncing | Emitted when the local copy of objects on a channel begins synchronizing with the Ably service.  |
| synced  | Emitted when the local copy of objects on a channel has been synchronized with the Ably service. |

```javascript theme={null}
channel.object.on('syncing', () => {
  console.log('Objects are syncing...');
  // Show a loading indicator and disable edits in the application
});

channel.object.on('synced', () => {
  console.log('Objects have been synced.');
  // Hide loading indicator
});
```

<Aside data-type="important">
  LiveObjects synchronization events do not replace connection or channel states. You should still monitor these states and handle connection and channel failures to ensure your application behaves as expected. LiveObjects synchronization events specifically inform you about the progress of LiveObjects data synchronization and should be used alongside other state management mechanisms.
</Aside>

## Handle object lifecycle events

### Detect object deletion

Objects can become unreachable when they are removed from the object tree using `remove()` and never reassigned. Unreachable objects are garbage collected by Ably, typically after 24 hours.

Since deleted objects are unreachable via any path, `object.delete` events can only be received through Instance subscriptions, which track a specific object by its ID regardless of its location in the object tree:

```javascript theme={null}
const counterInstance = myObject.get('visits').instance();

if (counterInstance) {
  counterInstance.subscribe(({ object, message }) => {
    if (message?.operation.action === 'object.delete') {
      console.log('Counter instance was deleted');
      // The client automatically unsubscribes the subscription after this notification
      // Remove references to this object from your application
    } else {
      console.log('Counter updated:', object.value());
    }
  });
}
```

In most cases, you don't need to explicitly handle object deletion. Your application should have already reacted to object removal when a corresponding `LiveMap.remove()` operation was received. However, if your application separately stores references to object instances and does not properly clear them when objects are orphaned, any later interactions with those objects after they are deleted will result in an error. In such cases, handling deletion events via Instance subscriptions helps ensure that those references are cleaned up and runtime errors are avoided.

<Aside data-type="note">
  The channel object cannot be deleted, so deletion notifications will never occur for the channel object itself.
</Aside>
