fix a bug that use static array will cause a huge memory leak by using linked list, and change some methods to get memory