Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: OSALoad and leaking handle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OSALoad and leaking handle



Micah,

In your example, I don't see where the script resource is being disposed,
but I'm going to assume that the StResource class instance takes care of
that.

Your sample code doesn't show how you are actually loading and unloading
the script in the AppleScript component (OSALoad & OSADispose). If you
are disposing the ScriptID before releasing the component instnace this
could very well be a leak in AppleScript itself.

andy b


On 03/15/01 10:36 PM, Micah Koch <email@hidden> wrote

> I was recently debugging a memory leak in my app using MW
>ZoneRanger to check for leaks. After I found the major one I noticed there
>were still a few small ones, so one by one I eliminated the leaks.
>Eventually I got done to one leak, it would appear that each call I make to
>OSALoad causes a handle to be leaked. I created the following class as a
>demonstration(I realize I don't check error return codes, the code is just
>for the purpose of example). I use a few PowerPlant classes in it, if you
>are unfamiliar with them, let me know and I'll clarify. If I just
>construct an object, and then destroy it I see no leaks. I get a handle
>leak according to ZoneRanger if I make a call to Load Script in between
>object construction and destruction. Curiously enough if I load an AEDesc
>with a text version of the script and use OSACompile instead then I get no
>leaks. The leak occurs whether or not I actually call OSAExecute to
>execute the script. Am I doing something wrong? Thanks,
>Micah
>
>ASLoader.h:
>
>class ASLoader {
>public:
> ASLoader(const FSSpec& inFileSpec);
>
> ~ASLoader();
> void LoadScript();
>protected:
> ComponentInstance mScriptingComponent;
> OSAID mScriptID;
> StAEDescriptor mCompiledScript;
>};
>
>ASLoader.cpp:
>
>#include "ASLoader.h"
>
>ASLoader::ASLoader(
> const FSSpec& inFileSpec)
>{
> mScriptID = kOSANullScript;
> mScriptingComponent = NULL;
>
> LFile resFile(inFileSpec);
> resFile.OpenResourceFork(fsRdPerm);
> StResource scriptHandle(kOSAScriptResourceType, 128, true, true);
>
> UAEDesc::AddPtr(&mCompiledScript.mDesc,0,typeOSAGenericStorage,*(scriptHa
>ndle.G
>et()),::GetHandleSize(scriptHandle.Get()));
> resFile.CloseResourceFork();
>
> mScriptingComponent = ::OpenDefaultComponent(kOSAComponentType,
>kAppleScriptSubtype);
>}
>
>ASLoader::~ASLoader()
>{
> if(mScriptingComponent)
> {
> if(mScriptID != kOSANullScript)
> ::OSADispose(mScriptingComponent,mScriptID);
>
> ::CloseComponent(mScriptingComponent);
> }
>}
>
>void
>ASLoader::LoadScript()
>{
> ::OSALoad (mScriptingComponent, &mCompiledScript.mDesc,
>kOSAModeNull, &mScriptID);
>}




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.