Sign in to follow this  
Followers 0
Zohar

How to Release/Delete an Object that was Created with ObjCreate()

12 posts in this topic

Hi

 

Like the title says, how can I do it?

 

Thank you

Share this post


Link to post
Share on other sites



$obj = 0 ; this will destroy the object

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

What kind of object are you creating that you need to specifically destroy? Typically, once that object goes out of scope (you close the IE window, or the application object, etc.), you're done.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$obj = 0 ; this will destroy the object

Thank you MikahS, but it didn't work.

It did not release the object..

 

What kind of object are you creating that you need to specifically destroy? Typically, once that object goes out of scope (you close the IE window, or the application object, etc.), you're done.

I created a DLL in .NET, and made it COM Visible, so AutoIt can see it and instantiate classes from it.

I then create an object of a class from that DLL, inside AutoIt, using ObjCreate().

When I am done with the object, the DLL file is still locked - I cannot recompile its source to a newer version..

Only until I close my AutoIt script.

I want to be able to recompile without closing the whole AutoIt script...

 

Any one knows what I can do?

Edited by Zohar

Share this post


Link to post
Share on other sites

Hmm, try

$obj = null
$obj = ""

 

Got it from here: >link


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Or (silly enough) post your script so we can see what you're doing rather than guessing :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hmm, try

$obj = null
$obj = ""

Got it from here: >link

null doesn't compile even..

There's no null in AutoIt..

"" leads to the same result as before.. still not released

 

Or (silly enough) post your script so we can see what you're doing rather than guessing :)

My code is quite simple:

Local   $Form   =ObjCreate("Namespace.Form_SomeForm")
MsgBox( $Form.SomeMethod($File_FullPath) )
$Form=0

The SomeMethod() method only returns after a button on the form is pressed,

which closes the form, and returns a value(the chosen button).

Edited by Zohar

Share this post


Link to post
Share on other sites

null doesn't compile even..

There's no null in AutoIt..

 

You are mistaken, as

Null
is definitely an AutoIt value. Set a variable to = Null and you'll see that it is fine ;)

 

This worked for me.

Local $obj = ObjCreate("shell.application")
MsgBox(0, "", $obj)
$obj = 0
MsgBox(0, "", $obj)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

 

You are mistaken, as

Null
is definitely an AutoIt value. Set a variable to = Null and you'll see that it is fine ;)

 

 

I did try it, and it was not fine,

but since you say it works for you, then I guess it's not working for me because I am not using the latest AutoIt version.

I use v3.3.6.1.

 

In any case, 0 and "" did compile well,

yet did not lead to the desired result..

Assuming null works the same, then it means it's not going to give it too.

(but this is only an assumption. to know for sure requires comparing the result between 0 and "", and between Null)

 

This worked for me.

Local $obj = ObjCreate("shell.application")
MsgBox(0, "", $obj)
$obj = 0
MsgBox(0, "", $obj)

 

Please note one important thing regarding that code:

The fact that the MsgBox showed that $obj=0, doesn't mean the object itself was released, it just means $obj is not referencing it anymore..

 

Maybe there's an explicit way to release an object?

Maybe an API function or something like that?

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

No idea if this is going to help, but maybe

_MemGlobalFree($obj)

?

EDIT: This is not a global memory object though, so I think you might need to do some serious digging. As, >this is where I got the solutions given before.

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

No idea if this is going to help, but maybe

_MemGlobalFree($obj)

?

EDIT: This is not a global memory object though, so I think you might need to do some serious digging. As, >this is where I got the solutions given before.

 

Unfortunately _MemGlobalFree($obj) did not succeed too.

 

It's interesting, since closing my script, frees the DLL very well.

So only by restarting my script, am I able to unlock the DLL, so I can recompile it.

I will read the post you linked to,

I hope it will help..

Thank you

 

You should code a way to destroy the object into your dll.

 

I would be glad to do it, if only I knew what can help.

 

The DLL is a .NET DLL, that I wrote in C#.

I selected the "Register for COM Interop" checkbox in the Project Properties (in the "Build" tab).

I added a [system.Runtime.InteropServices.ComVisible(true)] attribute to the class.

Both these steps are necessary, so AutoIt will be able to see and ObjCreate() the class in that DLL.

 

It all works well, except of finishing.

 

Specifically, my class is a Form,

and the method I run from AutoIt on that class, is a method that shows that form, waits for a button click, and then closes the form.

The method then returns the Name of the Button that was pressed.

 

In .NET, there is GC.Collect() for freeing up the memory from objects that are no longer referenced.

The problem is, that when the form is about to close, doing GC.Collect() will not help, since the form did not disappear yet - the command(GC.Collect()) will run when still inside it, so it will not do anything to it.

 

I thought about doing a trick:

To create a method that will reside outside that form's class, and that method will close the form, and perform GC.Collect().

The problem is, that If I do it, then the form will disappear, but the other class will still be alive when it is calling GC.Collect().

So I am still having one class alive, when doing GC.Collect()... and can't run away from it.

 

There should be a solution inside the AutoIt world, since when I close my script, the DLL is finally unlocked, and I am able to recompile it.

So far it's the only solution that worked.

If I could do it without closing the script, it would be better.

 

BTW:

Also when using Sysinternals Process Explorer, it shows that my AutoIt script's process is still holding a handle to the DLL I am calling, even after $obj=0.

(not that I needed to see it in Process Explorer to know it - I know it by the fact that the DLL's file is locked until I completely exit my script)

Edited by Zohar

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0