当c:l文件时,erlang内存会长大

时间:2018-09-11 04:06:32

标签: memory erlang

我找到了一个问题,但是我不确定这是bug还是其他错误,并且我不知道如何处理。

我一次将c:l(test_data)文件两次,发现关系进程的内存全部长大。 这是我的测试。

Os:Linux或Win

Erlang版本:R19或R20

Dir:erl_test

文件: test_server.erl,test_statem.erl,test_fsm.erl,test_data.erl,test_server2.erl。

test_data.erl是1M大文件。

运气是:

erl -s make all
erl
main:c(1).        %% will make 4 process: fsm , statem, server
observer:start(). %% open observer, see process memory
main:l().         %% will reload test_data.erl
                  %% look 4 processes memory
main:l().         %% reload test_data again 
                  %% look 4 processes memory, become large

main.erl和test_server.erl代码:

%% main.erl
-module(main).
-export([c/1, l/0]).

%% make process
c(N) ->
    test_fsm:create_mon(N),
    test_statem:create_mon(N),
    test_server:create_mon(N),
    test_server2:create_mon(N),
    ok.

%% reload test_data
l()->
    c:l(test_data).

%% test_server.erl, test_fsm, test_statem's code the same as test_server
-module(test_server).
-behaviour(gen_server).
%% API
-export([start_link/0, create_mon/1]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
-define(SERVER, ?MODULE).
-record(state, {mon = undefined}).

create_mon(0) -> ok;
create_mon(N) -> 
    start_link(),
    create_mon(N-1).

start_link() ->
    gen_server:start(?MODULE, [], []).

init([]) ->
    erlang:send_after(10000, self(), init),
    {ok, #state{mon = test_data:get(1)}}.

...

handle_info(_Info, State) ->
    Mon = test_data:get(1),
    erlang:send_after(10000, self(), info),
    {noreply, State#state{mon = Mon}}.

...

%%test_data.erl
-module(test_data).
-export([get/1]).
-include("test.hrl").

get(1) ->
     #mon{id = 1,name = "test", kind = 10,boss = 0,type = 0,career = 0,color 
           = 1,auto = 0,icon = 5010011,icon_scale = 1,icon_effect = 
           "",icon_texture = 0,weapon_id = 5010011,foot_icon = 0,desc = 
           "",lv = 1,hp_lim = 1000,att = 0,def = 0,hit = 0,dodge = 0,crit = 
           0,ten = 0,wreck = 0,resist = 0,special_attr = [],resum = 
           [],striking_distance = 0,tracing_distance = 0,warning_range = 
           0,hate_range = 0,speed = 0,skill = [{1110000003,1}],retime = 
           0,att_time = 0,att_type = 0,drop = 0,exp = 100,out = 
           0,collect_time = 0,collect_count = 0,is_fight_back = 
           0,is_be_atted = 1,is_be_clicked = 1,is_armor = 0,del_hp_each_time 
           = [10,10],figure_visible = 1,is_hide_hp = 0,is_hit_ac = 
           0,exp_share_type = 0,anger = 0};
...
get(10000) ->
    ...
....

图像是观察者的结果:enter image description here

0 个答案:

没有答案