Memory Leak on Apple's Part?

So I recently discovered the “set alpha value of window whatever” function in ASS, and I thought it was better than the Cocoa calls I had been making to do this before.

However, I think Apple has some sort of memory leak or something. When I wrote the following function, the program faced such major slowdown AFTER the function finished that the App was nearly unusable:


on WindowFade(myWindow, myState) --true is fading in, false is fading out
	if myState = false then
		set Al to 1
		repeat until Al ≤ 0.05
			set Al to Al - 0.02
			set alpha value of myWindow to Al
		end repeat
		hide myWindow
		set alpha value of myWindow to 1
	else
		set Al to 0
		set alpha value of myWindow to Al
		show myWindow
		repeat until Al = 1
			set Al to Al + 0.02
			set alpha value of myWindow to Al
		end repeat
		hide myWindow
	end if
	log "Done Fading"
end WindowFade

Granted, this is slightly intensive (changing the values a large number of times), but it happens fast enough that I don’t believe that to be the cause.

Does anyone know why? Is it an error on my part, or Apple’s?

Thanks,

SuperScripter

I haven’t tried the set alpha value to-command, but the method I use (call method “setAlphaValue:”) works just fine:

on clicked theObject
	repeat
		fadeWindowOut(window 1)
		delay 0.5
		fadeWindowIn(window 1)
		delay 0.5
	end repeat
end clicked

on fadeWindowOut(aWindow)
	set AV to alphaValue(aWindow)
	repeat while AV > 0.02
		set AV to AV - 0.01
		setAlphaValue(aWindow, AV)
	end repeat
	setAlphaValue(aWindow, 0)
end fadeWindowOut

on fadeWindowIn(aWindow)
	set AV to alphaValue(aWindow)
	repeat while AV < 0.98
		set AV to AV + 0.01
		setAlphaValue(aWindow, AV)
	end repeat
	setAlphaValue(aWindow, 1)
end fadeWindowIn

on setAlphaValue(aWindow, newValue)
	call method "setAlphaValue:" of aWindow with parameter newValue
end setAlphaValue

on alphaValue(aWindow)
	set v to (call method "alphaValue" of aWindow)
	return v
end alphaValue

Hope it helps,
ief2

Yeah, I was using that before, but I thought “Well, why not use the ‘official’ AppleScript method? It should be better, right?” Well, I guess not.

-SuperScripter

The “official” Applescript method, as you put it, is actually a… how do I properly describe this?.. an alternate way of running an Objective C/Cocoa command. (My analogy might be off just a bit here.) But “real” apps are built in Cocoa, and to give Applescript support, internal variables must be “exposed” to the Applescript system. Functions must be given alternate names and ways to address their input variables. Sometimes elaborate methods must be written to make sure that if an Applescript command changes a variable in the app’s memory, the app is alerted. So I would not think that any Applescript command is as efficient or hardy as the actual ObjC method.
The Matt Neuburg book has a section on this. That chapter made my brain hurt.

Chris