I am new learner on Erlang, I have questions about Erlang variable's life cycle.
Reference from Erlang gen_server comunication
-module(wy).
-compile(export_all).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
-behaviour(gen_server).
-record(state, {id ,m, succ, pred}).
start(Name, M) ->
gen_server:start_link({local, Name}, ?MODULE, [Name, M], []).
init([Name, M]) ->
{ok, #state{id = Name, m = M}}.
handle_call({get_server_info}, _Frome, State) ->
{reply, State, State};
handle_call(_Request, _From, State) ->
Reply = ok,
{reply, Reply, State}.
handle_cast(_Msg, State) ->
{noreply, State}.
handle_info(_Info, State) ->
{noreply, State}.
terminate(_Reason, _State) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
get_server_info(ServerName) ->
gen_server:call(ServerName, {get_server_info}).
What is the Variable "State" life cycle?
We can see variable "State" is reused from handle_call and handle_cast. First of all, are these "State" is the same one which is initialized from init() function "#state{id = Name, m = M}"
?
If so, is this "State" a global variable? When will this "State" be destroyed.
Does Erlang have global variables?