# How do i free memory when my master process ends?

**URL:** <https://www.ruby-forum.com/t/how-do-i-free-memory-when-my-master-process-ends/230141>\
**Category:** NGINX\
**Created:** [June 2, 2014, 12:46pm UTC](https://www.ruby-forum.com/t/how-do-i-free-memory-when-my-master-process-ends/230141 "2014-06-02T12:46:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason\_sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@jason\_sam](https://www.ruby-forum.com/u/jason_sam)\
**Post date:** [June 2, 2014, 12:46pm UTC](https://www.ruby-forum.com/t/how-do-i-free-memory-when-my-master-process-ends/230141/1 "2014-06-02T12:46:00Z")

</div>

I am allocating memory using malloc for some of my variables in my  
module.  
I know i can call an exit master process, but how do i access my  
variables  
in that function. I tried finding some examples, but didnt find any. Can  
anyone guide me through this.

---

<div class="post-metadata">

**Author:** ![Adarsh\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@Adarsh\_P](https://www.ruby-forum.com/u/Adarsh_P)\
**Post date:** [June 2, 2014, 5:56pm UTC](https://www.ruby-forum.com/t/how-do-i-free-memory-when-my-master-process-ends/230141/2 "2014-06-02T17:56:48Z")

</div>

Hello!

On Mon, Jun 02, 2014 at 04:15:09PM +0530, Adarsh P. wrote:

> I am allocating memory using malloc for some of my variables in my module.  
> I know i can call an exit master process, but how do i access my variables  
> in that function. I tried finding some examples, but didnt find any. Can  
> anyone guide me through this.

Resource allocation and deallocations are usually done with pools  
in nginx. If you want to do some allocations which aren’t from  
pool (e.g., an opened file, or a memory allocated directly with  
malloc() for some reason), it’s usually good idea to add a pool  
cleanup to do required deallocation when coresponding pool will be  
destroyed.

Try looking into the code for ngx\_pool\_cleanup\_add(), there are  
lots of examples.

–  
Maxim D.

> **[nginx](http://nginx.org/)**
