Mailing Lists: Apple Mailing Lists

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

Re: Disposing of data sources



This was a question on my list of issues with Xcode 3.0 that I had not posted yet.  In Xcode 2.5 and earlier, I was able to use "delete data source theDataSource" and my app would chug along just fine.  Now, I, too, get a GUI freeze when I try to delete data sources associated with tables.

I also had to convert the Window settings in my NIBs when I upgraded to XCode 3.0 to NOT "release when closed" when using "close window theWindow" because this will now also cause the GUI to freeze.

The response I have heard from some on this list is that we don't need to be concerned with the memory those objects (including data sources) are using; that the amount of memory they require is inconsequential.  I have never quite bought into this idea, mainly because it seems like bad form to leave all of these instances open all over the place.  I do have to admit, though, that I have not experienced any freezing or slowness in my apps when opening and closing a bunch of windows, tables, etc...

I would sure like to hear from Apple about these issues.  I have also posted some questions (and posted bug reports) over the last few weeks about some problems with XCode 3.0 for Leopard -- Xcode becoming extremely slow (when working with code), Xcode unexpectedly quitting on Building and Running an app, the Color Picker tool for background colors of tables not allowing the user to properly choose blended colors, the "Display Alert" function not showing alerts in front of open windows every time, etc.

In of the veterans of this group have any words of wisdom for us?

Thanks,

John

On May 25, 2008, at 9:13 PM, BareFeet wrote:

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

 _______________________________________________
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

References: 
 >Disposing of data sources (From: BareFeet <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.