express = require('express')
http = require('http')
redis = require('redis').createClient()
async = require('async')
port = 3000
app = express()
server = http.createServer(app)
class Cache
data = {}
constructor: ->
[@data](/user/data) = {}
get: (callback) ->
redis.get '1mb', (err, content) => # 每次从redis取出1mb数据
[@data](/user/data)[Math.random()] = content
callback(null, content)
foo = ->
for i in [0..1000]
cache = new Cache
cache.get (err, content) ->
foo() # 这个循环中的内存无法回收
app.get '/', (req, res) -> # 但是通过外部程序curl 1000次这个server,内存是可以得到回收的
cache = new Cache
cache.get (err, content) ->
res.send(content)
server.listen(port)
console.log "server listen on #{port}"