How can I destroy or unset session? I create module with many sessions . I want unset all session after module work . When I use session_destroy(); end of my module code , I have error and after that my sessions seem delete (session_unset(); not worked) . but after 4 or 5 time refresh page all sessions show to me .

Error:

Warning: session_destroy(): Trying to destroy uninitialized session in Drupal\...


How can I fix this problem in my drupal 8 ?
Don't use low level session_destroy(), use the session manager instead:

\Drupal::service('session_manager')-&gt;destroy();


This will remove all session data and the user is logged out, if that's what you want. You still get a warning if there is no session, so you might want to check this first. 

A better solution might be to use the symfony Session object

$request = \Drupal::request();
$request-&gt;getSession()-&gt;clear();


if you have set the session data in the request object or

$_SESSION = [];


if you have used the deprecated $_SESSION superglobal.

Normally you don't destroy the session or clear all session data, because there might be other modules that also use session data. Simply remove session variables in the same place where you have set them.

$request = \Drupal::request();
$session = $request-&gt;getSession();
$session-&gt;set('mymodule.value', $value);

// remove later when you don't need the value anymore
$session-&gt;remove('mymodule.value');


When all modules removed their values the session is destroyed by Drupal automatically (for anonymous users).