Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Disposing of data sources



Hi All,

-- I'm Sending again with a "reply to" header, since this list is brain dead about replying. Please reply to the mail list.

Short question:

How should I delete a data source after its GUI display is removed, such as its window closed?

More detail:

In AppleScript Studio (Xcode using AppleScript) we populate the cells of a table by making and attaching a data source to it. Each time we make a new table (usually by opening a new window containing a table), we create a new associated data source.

When we no longer need a table, such as wen closing a window containing a table, we logically should delete the associated data source to recover the memory that it used. Otherwise our application will bloat every time we close a window and open another. I've had this happen with large tables or prolonged use of my application, where it eventually freezes or reports a memory error.

I looks at various sample applications, such as the "Mail Search" included with Xcode. They don't seem to dispose of data sources after being dismissed. There is no handling of a closed window. I thought that the now deprecated approach of adding a ASKDataSource object in Interface Builder would automatically handle the disposal of the associated memory when the window containing the instance as closed, but testing shows that the data source still exists after the associated table (and window) are closed.

So I figured we have to manually delete a data source when the associated window is closed. I created a "data source window links" list to keep track of data sources created for each window, then checks the list for any data sources to delete when the window closes. (The list is actually a data source itself since Xcode facilitates database like searching on it). Here's some sample code I tried:

property windowDataName : "data source window links"

on awake from nib theObject
if class of theObject is table view then
AddDataSourceLinkTo(theObject)
end if
end awake from nib

on will close theObject
DeleteDataSourcesOf(theObject)
end will close

on AddDataSourceLinkTo(theObject)
set newDataSource to make new data source at end in data sources
repeat with tableColumnRef in table columns in theObject
set myIdentifier to name of tableColumnRef
make new data column at end in newDataSource with properties {name:myIdentifier}
end repeat


if not (exists data source windowDataName) then
set linkDataSource to make new data source at end with properties {name:windowDataName}
tell linkDataSource
make new data column at end with properties {name:"data source id"}
make new data column at end with properties {name:"window id"}
end tell
end if
set newLinkDataRow to make new data row at end in data source windowDataName
tell newLinkDataRow
set contents of data cell "data source id" to id of newDataSource
set contents of data cell "window id" to id of window of theObject
end tell
set data source of theObject to newDataSource
end AddDataSourceLinkTo

on DeleteDataSourcesOf(theObject)
set myWindowID to id of theObject
set affectedLinkDataRows to every data row in data source windowDataName where contents of data cell "window id" is myWindowID
repeat with affectedLinkDataRow in affectedLinkDataRows
set myDataSourceID to contents of data cell "data source id" in affectedLinkDataRow
tell data source id myDataSourceID
delete
end tell
delete affectedLinkDataRow
end repeat
end DeleteDataSourcesOf

Am I correct in concluding that most or all ASS projects out there have a major memory leak issue when opening and closing tables? Is there a more straight forward way to handle the problem than my solution above?

My above simple example works fine. But in another real world project, the GUI freezes in my app whenever I delete the data source. I'm guessing it's because it's deleting the data source before my app has disposed of the window containing it (ie before the "on will close" handler has finished. Is there a way around this?

Thanks,
Tom
BareFeet

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Studio mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden



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

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.