Question: What is the language construct that corresponds to python `del` statement in Ruby. By what other means I can explicitly release memory in Ruby.

Answer: 
> 
> Is there any corresponding method of del in Python for Ruby?
> 
> 
> 

`del` does many different things in [python](/questions/tagged/python "show questions tagged 'python'"). In [ruby](/questions/tagged/ruby "show questions tagged 'ruby'"), it is generally preferred that a method do only one thing, so there are many methods that provide different aspects of what `del` does in Python.

Unfortunately, it is rather hard to tell, what *exactly* `del` does in Python. Here's a pretty telling [quote from the Language Reference](https://Docs.Python.Org/3.5/reference/simple_stmts.html#the-del-statement):

> 
> Rather than spelling it out in full details, here are some hints.
> 
> 
> 

* For deleting an entry from an [`Array`](http://Ruby-Doc.Org/core-2.1.2/Array.html), use [`Array#delete_at`](http://Ruby-Doc.Org/core-2.1.2/Array.html#method-i-delete_at)
* For deleting a slice from an `Array`, use [`Array#slice!`](http://Ruby-Doc.Org/core-2.1.2/Array.html#method-i-slice-21)
* For removing an entry from a [`Hash`](http://Ruby-Doc.Org/core-2.1.2/Hash.html), use [`Hash#delete`](http://Ruby-Doc.Org/core-2.1.2/Hash.html#method-i-delete)
* For removing an instance variable, use [`Object#remove_instance_variable`](http://Ruby-Doc.Org/core-2.1.2/Object.html#method-i-remove_instance_variable)
* For removing a class variable, use [`Module#remove_class_variable`](http://Ruby-Doc.Org/core-2.1.2/Module.html#method-i-remove_class_variable)
* For removing a constant, use [`Module#remove_const`](http://Ruby-Doc.Org/core-2.1.2/Module.html#method-i-remove_const)
* For removing a local variable, there is no method in Ruby. Local variables go out of scope at the end of a block, method, class, module or script body, and those should be small anyway, so in general, you shouldn't need to explicitly remove local variables. If you need to limit the scope of a local variable, you can always wrap it in a block:

```
# some code here
-> {
  some_local_var = 'blah'
  # code using some_local_var
}.()
# more code here, some_local_var is no longer in scope

```
* There's also no method for removing a global variable. Global variables should only be used in quick, short, throwaway scripts, where it doesn't matter.

> 
> Or, how should I release the memory space in Ruby?
> 
> 
> 

Ruby has automatic memory management (just like Python, BTW). It will release the memory for you.
At the Python's Language Reference, there's this part of what del does:

> 
> Deletion of a name removes the binding of that name from the local or
>  global namespace.
> 
> 
> 

In Ruby, there’s no way to unset a variable once set. You can set a variable to nil, which allows it to be GC, but the variable will remain in the symbol table as long as it is in scope.