与Sinatra App建立api。
每个请求都是15MB。每次刷新页面时都会增加15MB的内存。如何在每次请求后清除信息?
require 'rubygems'
require 'sinatra'
require 'active_record'
require 'mysql2'
require 'json'
client = Mysql2::Client.new(adapter: 'mysql2', host: '127.0.0.1', database: 'dev_app', username: 'root', password: 'root')
get '/people' do
q = "select name, age from people;"
people = client.query(q, :as => :json).map{|one| {one['name'] => one['age'].to_i}}
return people.to_json
people = nil
end
答案 0 :(得分:1)
您还没有确定应用程序中实际消耗的内存。因此,您的问题是未定义的,任何“解决方案”都会在寻找潜在答案时挣扎。
答案 1 :(得分:0)
不确定这是否重要,但我很确定你的'/ people'块的最后一行不会被调用,因为你有明确的回报
return people.to_json # this exits the block
people = nil #this never gets called.