我的应用程序在接收特定事件时释放了大量内存。这是活动前的mallinfo统计数据。
INFO sas2 - Total non-mmapped bytes (arena): 181747712
INFO sas2 - # of free chunks (ordblks): 14340
INFO sas2 - # of free fastbin blocks (smblks): 17
INFO sas2 - # of mapped regions (hblks): 36
INFO sas2 - Bytes in mapped regions (hblkhd): 139460608
INFO sas2 - Max. total allocated space (usmblks): 0
INFO sas2 - Free bytes held in fastbins (fsmblks): 912
INFO sas2 - Total allocated space (uordblks): 175712192
INFO sas2 - Total free space (fordblks): 6035520
INFO sas2 - Topmost releasable block (keepcost): 60112
处理事件后的统计数据是
INFO sas2 - Total non-mmapped bytes (arena): 181747712
INFO sas2 - # of free chunks (ordblks): 797
INFO sas2 - # of free fastbin blocks (smblks): 0
INFO sas2 - # of mapped regions (hblks): 38
INFO sas2 - Bytes in mapped regions (hblkhd): 153735168
INFO sas2 - Max. total allocated space (usmblks): 0
INFO sas2 - Free bytes held in fastbins (fsmblks): 0
INFO sas2 - Total allocated space (uordblks): 1056528
INFO sas2 - Total free space (fordblks): 180691184
INFO sas2 - Topmost releasable block (keepcost): 238368
正如您所看到的,fordblks指示了大约180MB的可用内存。虽然应用程序释放了内存,但malloc似乎并没有将其恢复到内核。由于我的系统已经受到内存限制,我不能失去这么大的内存。有没有办法可以强制释放fordblks指示的字节?
我尝试过malloc_trim并没有帮助。正如您所看到的,它只是释放了“keepcost”字节。