|
Hello everyone! I have some issues with the GC, and how it works. First I try to run the following script. It reached the max 512m RES memory usage, and drops to 1000b just after collectgarbage call. local clock = os.clock t = {} t[1] = {} for i=0, 20000000 do table.insert(t[1],i) end print ("Heap Size1:" .. collectgarbage('count')/1024) t[1] = nil print ("Done.") collectgarbage("collect") print ("Heap Size2:" .. collectgarbage('count')/1024) local t0 = clock() while clock() - t0 <= 30 do end Top PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 17909 mozturk 25 0 527m 512m 684 R 99.4 0.2 0:07.17 lua PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 20090 mozturk 25 0 15368 1000 752 R 98.6 0.0 0:10.54 lua Prints: Heap Size1:512.028673172 Done. Heap Size2:0.026923179626465 Second when I just change "i" to "{i}" (mark it bold) which I really wanted (I minimize the code for clearity.) the RES memory goes up to 2.6g and drops to 2.1g just after collectgarbage call. local clock = os.clock t = {} t[1] = {} for i=0, 20000000 do table.insert(t[1],{i}) end print ("Heap Size1:" .. collectgarbage('count')/1024) t[1] = nil print ("Done.") collectgarbage("collect") print ("Heap Size2:" .. collectgarbage('count')/1024) local t0 = clock() while clock() - t0 <= 30 do end PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 25207 mozturk 25 0 2663m 2.6g 736 R 98.6 1.0 0:21.81 lua PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 25207 mozturk 25 0 2663m 2.1g 736 R 98.6 1.0 0:21.81 lua Prints: Heap Size1:2037.9059820175 Done. Heap Size2:0.026938438415527 The question is why do GC reports different than os system. Why doesn't it reclaim the pyhsical memory? Best Regards. System info: [mozturk@pacific bin]$ ./lua Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio > [mozturk@pacific bin]$ gcc -v Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux Thread model: posix gcc version 4.1.2 20080704 (Red Hat 4.1.2-48) [mozturk@pacific bin]$ uname -a Linux pacific 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux |