Session: How to Clear a Session

To clear session state, stop tracking entities, and remove all pending commands, use the clear method from the advanced session operations.

Syntax

public function clear(): void;

Example

$employee = new Employee();
$employee->setFirstName("John");
$employee->setLastName("Doe");
$session->store($employee);

$session->advanced()->clear();

$session->saveChanges(); // nothing will hapen