标签:style blog http color 使用 os
目前我开发的一个服务器后台程序存在这么一个问题,由于我的程序要不断的收发消息,并做统计,统计用的是stl的多重map,在统计中会不断的往map里赛数据。但是每次统计后我都会调用clear()去释放内存,但是似乎并不奏效,仍然会有泄漏的现象。查资料,map的clear是将map内容清空,但是内存并不归还给系统,而是缓冲在内存池里以方便下次调用,有人提出,可以新建一个map,将两个map做swap操作,互换内容,然后delete这个新map,达到释放的效果,但是不奏效。我也想到多重map,是否需要将多重map里的小map对象也一一clear,然后再clear这个多重map,但是也不奏效。难道stl真的存在这个问题吗?
如下是机器cat /proc/meminfo的内容:
MemTotal: 23929284 kB MemFree: 1238556 kB Buffers: 198708 kB Cached: 16489584 kB SwapCached: 0 kB Active: 7130900 kB Inactive: 10959804 kB Active(anon): 1402564 kB Inactive(anon): 2504 kB Active(file): 5728336 kB Inactive(file): 10957300 kB Unevictable: 0 kB Mlocked: 0 kB SwapTotal: 10485752 kB SwapFree: 10485752 kB Dirty: 312 kB Writeback: 0 kB AnonPages: 1402460 kB Mapped: 19048 kB Shmem: 2616 kB Slab: 2303932 kB SReclaimable: 1053828 kB SUnreclaim: 1250104 kB KernelStack: 1896 kB PageTables: 15248 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 22450392 kB Committed_AS: 2153752 kB VmallocTotal: 34359738367 kB VmallocUsed: 71416 kB VmallocChunk: 34359661160 kB HardwareCorrupted: 0 kB AnonHugePages: 0 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 24576000 kB DirectMap2M: 0 kB
"Free," "buffer," "swap," "dirty." What does it all mean? If you said, "something to do with the Summer of ‘68", you may need a primer on ‘meminfo‘.
The entries in the /proc/meminfo can help explain what‘s going on with your memory usage, if you know how to read it.
Example of "cat /proc/meminfo":
root: total: used: free: shared: buffers: cached: Mem: 1055760384 1041887232 13873152 0 100417536 711233536 Swap: 1077501952 8540160 1068961792
MemTotal: 1031016 kB MemFree: 13548 kB MemShared: 0 kB Buffers: 98064 kB Cached: 692320 kB SwapCached: 2244 kB Active: 563112 kB Inact_dirty: 309584 kB Inact_clean: 79508 kB Inact_target: 190440 kB HighTotal: 130992 kB HighFree: 1876 kB LowTotal: 900024 kB LowFree: 11672 kB SwapTotal: 1052248 kB SwapFree: 1043908 kB Committed_AS: 332340 kB
The information comes in the form of both high-level and low-level statistics. At the top you see a quick summary of the most common values people would like to look at. Below you find the individual values we will discuss. First we will discuss the high-level statistics.
VM splits the cache pages into "active" and "inactive" memory. The idea is that if you need memory and some cache needs to be sacrificed for that, you take it from inactive since that‘s expected to be not used. The vm checks what is used on a regular basis and moves stuff around.
When you use memory, the CPU sets a bit in the pagetable and the VM checks that bit occasionally, and based on that, it can move pages back to active. And within active there‘s an order of "longest ago not used" (roughly, it‘s a little more complex in reality). The longest-ago used ones can get moved to inactive. Inactive is split into two in the above kernel (2.4.18-24.8.0). Some have it three.
不能解决这个问题,我比较纠结。请大家帮忙了。
标签:style blog http color 使用 os
原文地址:http://blog.csdn.net/bg2bkk/article/details/37747499