# Out of Memory Exception

**URL:** <https://erlangforums.com/t/out-of-memory-exception/2177>\
**Category:** Questions / Help\
**Tags:** memory, erl\_driver\
**Created:** [December 16, 2022, 6:12am UTC](https://erlangforums.com/t/out-of-memory-exception/2177 "2022-12-16T06:12:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![joseph](https://erlangforums.com/user_avatar/erlangforums.com/joseph/32/1058_2.png) [@joseph](https://erlangforums.com/u/joseph)\
**Post date:** [December 16, 2022, 6:12am UTC](https://erlangforums.com/t/out-of-memory-exception/2177/1 "2022-12-16T06:12:42Z")

</div>

I am working on an application that needs to transfer high amount of data via udp. I have written an erl\_driver to pull data off an interface as fast as I can. I am using driver\_alloc\_binary() for allocating binaries for reading data into. After I transfer the binary to the port owner, I call driver\_free\_binary().

Here is an example of how I am reading the data.

```erlang
while (true) {

auto pBinary = driver_alloc_binary();

if (pBinary == nullptr) {
  printf("ERROR: Ran out of memory\r\n");
  continue;
}

auto readCount = read(pBinary, ...);

driver_free_binary(pBinary);
}

```

I am also sending out data. I implemented the outputv callback, and call writev function to write the IO vector to the interface.

After running for short period of time, The VM dies on me with the message “Killed”. By looking at the logs, I can see that it died because of an out of memory (OOM) exception. I know this is really vague, but does anyone have some pointers on how I can debug this. I’m not sure how to use the various tools that are exists, nor do I know which tools would be best for this. For what it’s worth, the system runs on a server that is memory constraint to 2GB of memory.
