fix bug when removing the context in memory mode