add error handle and mark check in memory.h