[erlang-questions] mmap file to binary

Max Lapshin <>
Wed Jul 14 09:53:03 CEST 2010

I have to do so:

    Mmap *mm;
    mm = (Mmap *)enif_alloc_resource(mmap_resource, sizeof(Mmap));

    mm->ptr = m;
    mm->size = (size_t)file_stat.st_size;

    m_bin = enif_make_resource_binary(env, mm, mm->ptr, mm->size);
    enif_release_resource(mm);   % <---------
    return enif_make_tuple2(env, enif_make_atom(env, "ok"), m_bin);

If I don't add enif_release_resource, it will never be garbage
collected. Why I have to do so?

More information about the erlang-questions mailing list