# Memory usage with elastic-apm-node and custom transactions

**URL:** <https://discuss.elastic.co/t/memory-usage-with-elastic-apm-node-and-custom-transactions/124229>\
**Category:** APM\
**Created:** [March 16, 2018, 8:15am UTC](https://discuss.elastic.co/t/memory-usage-with-elastic-apm-node-and-custom-transactions/124229 "2018-03-16T08:15:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tallakh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallakh/32/8860_2.png) [@tallakh](https://discuss.elastic.co/u/tallakh)\
**Post date:** [March 16, 2018, 8:15am UTC](https://discuss.elastic.co/t/memory-usage-with-elastic-apm-node-and-custom-transactions/124229/1 "2018-03-16T08:15:38Z")

</div>

Hi,

We have started to use APM and elastic-apm-node to instrument our node application. We get a lot of great information from the express routes which has helped us a lot.

We have recently started to track background jobs as well using custom transactions, but there seems to be an issue with memory never being released when a custom transaction is closed. The application will continue to consume memory until it is out of memory and the application is restarted. The background jobs typically runs for a couple of minutes and generate some 200 spans, so I expect some additional memory usage. But when the transaction is closed I would assume the the memory is released.

We start a custom transaction like this:

```javascript
import * as APM from "elastic-apm-node";

const trans = APM.startTransaction("JobName", "Job");
try {
  await CacheRunner._runJob(taskDef, task.params);
} catch (err) {
  trans.result = 500;
  trans.end();
  throw err;
}
trans.result = 200;
trans.end();

```

---

<div class="post-metadata">

**Author:** ![wa7son](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wa7son/32/21259_2.png) [@wa7son](https://discuss.elastic.co/u/wa7son)\
**Post date:** [March 16, 2018, 9:24am UTC](https://discuss.elastic.co/t/memory-usage-with-elastic-apm-node-and-custom-transactions/124229/2 "2018-03-16T09:24:37Z")

</div>

Which version of the agent are you using?

We just released version 1.2.1, which a fix for a memory leak related to the V8 microtask queue.

---

<div class="post-metadata">

**Author:** ![tallakh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallakh/32/8860_2.png) [@tallakh](https://discuss.elastic.co/u/tallakh)\
**Post date:** [March 16, 2018, 9:50am UTC](https://discuss.elastic.co/t/memory-usage-with-elastic-apm-node-and-custom-transactions/124229/3 "2018-03-16T09:50:02Z")

</div>

I was running 1.1.1. I've tested again using the latest 1.2.1 which completely fixes the issue.  
Thanks for your quick reply.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 6, 2018, 5:50am UTC](https://discuss.elastic.co/t/memory-usage-with-elastic-apm-node-and-custom-transactions/124229/4 "2018-04-06T05:50:28Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
