Skip to content

Instantly share code, notes, and snippets.

@Laymer
Forked from ferd/refc_leak.erl
Created August 16, 2018 17:30
Show Gist options
  • Save Laymer/19462feab8610f0e63f43f296c21438b to your computer and use it in GitHub Desktop.
Save Laymer/19462feab8610f0e63f43f296c21438b to your computer and use it in GitHub Desktop.
Find Erlang processes that may be leaking refc binaries
f(MostLeaky).
MostLeaky = fun(N) ->
lists:sublist(
lists:usort(
fun({K1,V1},{K2,V2}) -> {V1,K1} =< {V2,K2} end,
[try
{_,Pre} = erlang:process_info(Pid, binary),
erlang:garbage_collect(Pid),
{_,Post} = erlang:process_info(Pid, binary),
{Pid, length(Post)-length(Pre)}
catch
_:_ -> {Pid, 0}
end || Pid <- processes()]),
N)
end.
%% Pairs = MostLeaky(25).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment