Posts Tagged ‘erlang’

Memory leak in erlang.

September 15, 2009

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”.


Object-Oriented on Erlang VM

September 6, 2009

Erlang is a *super* concurrent-oriented functional language.

Here, I listed some way to write object-oriented code for erlang. (Not just some shapes trick)

1. mudole as value.

ModuleName = math,
X = ModuleName:sqrt(16.0).

Ok, it’s not OO enough.

2. build-in parameter module and extends module.

f1() -> super_f1.

Try to call sub:f1().

-module(pmodule, [X]).
x() -> X.

And you can do this:

Obj = pmodule:new(cool),

It’s true. You can do it right now! Although these features are experimented. see Inheritance in Erlang.

3. other object-oriented languages run on erlang vm.


ruby-style, every object is a gen_server.

Now, it’s compiler just compile the reia code into the erlang code.

See slide.

ECT(Erlang Class Transformation)

add object-oriented programming to Erlang.

see Object-oriented extension to Erlang.

WOOPER(Wrapper for Object-Oriented Programming in Erlang)

eXAT(erlang eXperimental Agent Tool)

Too old.