Modify

Opened 14 years ago

Closed 13 years ago

#1656 closed Bug (No Bug)

Object not being released properly

Reported by: FuryCell Owned by: Jon
Milestone: Component: AutoIt
Version: 3.3.6.1 Severity: None
Keywords: Cc:

Description

The following code should release the iTunes object so a dialog about scripting being in use by iTunes will not appear. However it does not seem the object is released properly as iTunes still complains.

Global $oiTunes=ObjCreate("iTunes.application")
ObjEvent($oiTunes,"_Event_")

While 1
	Sleep(100)
WEnd

Func _Event_OnAboutToPromptUserToQuitEvent()
	Global $oiTunes=0
EndFunc   ;==>_Event_OnAboutToPromptUserToQuitEvent

From the iTunes documentation

The ITEventAboutToPromptUserToQuit event is fired when iTunes is about prompt the user to quit.

This event gives clients the opportunity to prevent the warning dialog prompt from occurring.

If the user attempts to quit iTunes while a client still has outstanding iTunes COM objects instantiated, iTunes will display a warning dialog. This event is fired just before the warning dialog is shown. iTunes will then wait up to 5 seconds for clients to release any outstanding iTunes COM objects. If all objects are released during this time, the warning dialog will not be shown and iTunes will quit immediately.

Otherwise, the warning dialog will be shown. If the user chooses to quit iTunes anyway, the ITEventQuitting event is fired. See _IiTunesEvents::OnQuittingEvent() for more details.

Attachments (0)

Change History (5)

comment:1 Changed 14 years ago by Jpm

  • Owner set to Jon
  • Status changed from new to assigned

comment:2 Changed 14 years ago by wraithdu

The problem here is that the call to ObjEvent() must be assigned to a variable that doesn't go out of scope. Once ObjEvent() becomes unassigned, the events are no longer received. This modified example works fine for me.

Global $exit = False
Global $oiTunes=ObjCreate("iTunes.application")
ConsoleWrite("isobj: " & IsObj($oiTunes) & @CRLF)
Global $event = ObjEvent($oiTunes,"_Event_")

Do
	Sleep(100)
Until $exit

Func _Event_OnAboutToPromptUserToQuitEvent()
	ConsoleWrite("exiting..." & @CRLF)
	$oiTunes=0
	$exit = True
EndFunc   ;==>_Event_OnAboutToPromptUserToQuitEvent

comment:3 Changed 14 years ago by anonymous

It works if the program exits because then the hooks are released but if the script is kept running it will not. This still does not work.

Global $exit = False
Global $oiTunes=ObjCreate("iTunes.application")
ConsoleWrite("isobj: " & IsObj($oiTunes) & @CRLF)
Global $event = ObjEvent($oiTunes,"_Event_")

Do
	Sleep(100)
Until 0

Func _Event_OnAboutToPromptUserToQuitEvent()
	ConsoleWrite("disposing of object..." & @CRLF)
	$oiTunes=0
	$exit = True
EndFunc   ;==>_Event_OnAboutToPromptUserToQuitEvent

comment:4 Changed 14 years ago by ProgAndy

I have no iTunes, so I can not test this:
I think you have to release also the event-object and not only the iTunes.Object.

Global $oiTunes=ObjCreate("iTunes.application")
ConsoleWrite("isobj: " & IsObj($oiTunes) & @CRLF)
Global $oITunes_event = ObjEvent($oiTunes,"_Event_")

Do
	Sleep(100)
Until 0

Func _Event_OnAboutToPromptUserToQuitEvent()
	ConsoleWrite("disposing of object..." & @CRLF)
	$oITunes_event = 0
	$oiTunes=0
EndFunc   ;==>_Event_OnAboutToPromptUserToQuitEvent

comment:5 Changed 13 years ago by trancexx

  • Resolution set to No Bug
  • Status changed from assigned to closed

This is not a bug. Proper handling for this particular "problem" is described inside the help file. Search it using this "stop rerouting events object is still holding a reference".
Use Stop method of the event object before releasing it.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jon.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.