Problem with DbSession

hi.
i use yii\web\DbSession class for session component.When I use Flash, the message is displayed but the flash is not removed. If I use yii\web\Session class, the problem will be solved. The problem is only when I use the DbSession class.

my code: (use in main layout)
<?php
$session = Yii::$app->session;

if($session->hasFlash(‘success’)) {
$msg=$session->getFlash(‘success’);
$this->registerJs("
noty(’".trim($msg)."’,‘success’);
“);
}
if($session->hasFlash(‘error’)) {
$msg=$session->getFlash(‘error’);
$this->registerJs(”
noty(’".trim($msg)."’,‘error’);
");
}
?>