# Win32ole and releasing COM objects

**URL:** <https://www.ruby-forum.com/t/win32ole-and-releasing-com-objects/156496>\
**Category:** Ruby\
**Created:** [December 29, 2008, 5:32am UTC](https://www.ruby-forum.com/t/win32ole-and-releasing-com-objects/156496 "2008-12-29T05:32:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![farmerss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/dbc845/32.png) [@farmerss](https://www.ruby-forum.com/u/farmerss)\
**Post date:** [December 29, 2008, 5:32am UTC](https://www.ruby-forum.com/t/win32ole-and-releasing-com-objects/156496/1 "2008-12-29T05:32:31Z")

</div>

Hi,

I’m using win32ole to automate use of Microsoft Office Document Imaging  
(MODI), on Windows Vista. There seems to be problems with getting MODI  
to release files that it works with. I.e., calling Close on the MODI  
object doesn’t necessarily release the file to other processes  
(attempting to delete it gives me an Errno::EACCESS error). A web search  
shows that this is a common issue, and the main suggestion in other  
languages is to use

System.InteropServies.Marshal.ReleaseComObject(object)

for each object that needs to be released. Do we have access to this  
method in Ruby? Or does anyone know another way to deal with this?

Thanks,  
Farmer.

---

<div class="post-metadata">

**Author:** ![farmerss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/dbc845/32.png) [@farmerss](https://www.ruby-forum.com/u/farmerss)\
**Post date:** [December 29, 2008, 7:13am UTC](https://www.ruby-forum.com/t/win32ole-and-releasing-com-objects/156496/2 "2008-12-29T07:13:12Z")

</div>

Farmer Schlutzenberg wrote:

> for each object that needs to be released. Do we have access to this  
> method in Ruby? Or does anyone know another way to deal with this?

Try WIN32OLE.ole\_free or WIN32OLE#ole\_free.

WIN32OLE.ole\_free(object)  
or  
object.ole\_free

FYI, Win32OLE automatically releases com object when the object  
is GCed. And Win32OLE does not release com object until the object  
is GCed (except WIN32OLE.ole\_free, WIN32OLE#ole\_free).

Regards,  
Masaki S.

---

<div class="post-metadata">

**Author:** ![farmerss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/dbc845/32.png) [@farmerss](https://www.ruby-forum.com/u/farmerss)\
**Post date:** [December 29, 2008, 8:39am UTC](https://www.ruby-forum.com/t/win32ole-and-releasing-com-objects/156496/3 "2008-12-29T08:39:00Z")

</div>

Thanks! That works great, just the sort of thing I was looking for.
