Memory leak in erlang.

Let’s talk about memory leak in java or .net first.

Maybe you think with auto Garbage Collection, there will no memory leak at all.

Suggest you write your own ArrayList. You pre-allocate a space when you create one. When you add more elements than your space, you allocate a new space twice as the old space, copy your data to the new space, and add new elements. It’s OK so far.

Now, we delete most of the elements, and, unlucky, you forgot free your space…

This is what we called memory leak in java or .NET. when you implement a ThreadPool, ObjectPool, HashTable, etc. be careful memory leak.

In  erlang, it’s nearly no cost to spawn a new process. And erlang encourage you create more processes. It’s erlang-style! We all like it!

All right.

Now I just port a java project to erlang. I make most of abject a gen_server. It’s natural. And It’s dangerous.

GC won’t free your gen_server, you need terminate it BY YOURSELF!! Every actors are everlasting, you need KILL them with your hands!

Any best practice for this kinda memory leak? Do not tell me “Supervisor + start_link”.


Tags: ,

2 Responses to “Memory leak in erlang.”

  1. Yogish Baliga Says:

    Why do you think gen_server will have memory leak? Can you give me some example where you found the memory leak within gen server?

    • iron9light Says:

      Maybe I just misuse the gen_server. I just port a project from java to erlang. So I just replace many classes by gen_server.
      It’s not memory leak, or I should call it “process leak”.
      I’m new to erlang. Tell me if I’m wrong.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: