A little clarity on custom Obj-C Classes...

External developers... This forum's for you!

A little clarity on custom Obj-C Classes...

Postby Dave_Higgins » Mon Sep 13, 2010 6:29 pm

Mark. I was chatting with Uli a while back when he taught me a good deal about custom classes running in externals, and I'd like to verify if it still applies, and have a question about them as a result of that...

He was telling me about how classes need unique names (best done with a #define, so the compiler will actually give a class a long unique name including, say, the external name and maybe a version) to avoid collisions. He said that SC can't unload custom Obj-C classes, and that the first one in wins. So if I have a class in one external called "Accounts" (without any #defined long name), and then another external has a class of the same name, that the second external wouldn't be able to see it's own "Accounts" class and would try to operate with the first one, which may not have the same methods and iVars/properties in place.

Does all this still apply with later versions of SC? He said it's been quite a while since he's had to deal with it, and pretty much avoided it all along with the #define names.

And the question about them... When a same external is run over and over (or in the case above where it's called the same between two), does SC see that the class is already loaded and just ignore loading any new copies? I'm just wanting to see if I'm thinking this out right that we're not piling up unusable copies of a class over and over with the first one being the only one that can be used. I assume it's not being replaced with the newest run, given the issue mentioned above.

Or is there something added in recent versions that now allows older classes to be flushed out that Uli's not aware of, having been away from externals development for so long? Maybe something along the lines of hasMemory(), where the SLG states Issuing the hasMemory function with the memorySize option will purge these stored object definitions in an attempt to supply the memory space requested in memorySize. ... only dealing with classes instead of SC's own object definitions.
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon

Re: A little clarity on custom Obj-C Classes...

Postby codegreen » Tue Sep 14, 2010 12:08 am

Dave Higgins wrote:He was telling me about how classes need unique names (best done with a #define, so the compiler will actually give a class a long unique name including, say, the external name and maybe a version) to avoid collisions. He said that SC can't unload custom Obj-C classes, and that the first one in wins. So if I have a class in one external called "Accounts" (without any #defined long name), and then another external has a class of the same name, that the second external wouldn't be able to see it's own "Accounts" class and would try to operate with the first one, which may not have the same methods and iVars/properties in place.

Does all this still apply with later versions of SC? He said it's been quite a while since he's had to deal with it, and pretty much avoided it all along with the #define names.

This is the big problem with writing externals using Cocoa, and the reason why I never do it or recommend it. Last I checked, Cocoa was designed from the ground up with the assumption that code never gets unloaded. There is a limited scope within which you can get away with it (basically if you ensure nobody -- e.g. an auto-release pool -- will try to invoke your class after it's gone) but the Cocoa docs make it pretty clear that as a rule of thumb it's a long ride off a short pier.

And the question about them... When a same external is run over and over (or in the case above where it's called the same between two), does SC see that the class is already loaded and just ignore loading any new copies?

Unlike the old CFM varieties universal externals normally aren't unloaded between calls, just when the resource is deleted or the owning project is closed. SC takes care not to unload an external while it is still nominally running, but SC can't protect you from Cocoa going into a ditch afterwards if someone else tries to call through a dangling retained reference to it.

-Mark
codegreen
 
Posts: 1510
Joined: Mon Jul 14, 2008 11:03 pm

Re: A little clarity on custom Obj-C Classes...

Postby Dan_Kelleher » Tue Sep 14, 2010 11:13 am

Dave,
Are you using, 'Reference Counting' (p15 of the "Obj-C P-Guide" and the, "Mem. Management P-Guide") to control memory management (rather than the, "Garbage collection" system)?

Are you using, "Static typing", which, I read, could provide additional benefits related to your need to control and avoid confusions (p91-94 of the "Obj-C P-Guide") ?

I remember thinking that both these options might be the way to go in order to build the code in the most explicit
manner and therefore not only easier to read but also more, what's the word... ? whatever it is, it means stable and less likely to break. (as usual, I'm not actually doing this now so I can't be more specific & helpful)
-Dan
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: A little clarity on custom Obj-C Classes...

Postby Dave_Higgins » Wed Sep 15, 2010 10:38 am

KelleherD wrote:Dave,
Are you using, 'Reference Counting' (p15 of the "Obj-C P-Guide" and the, "Mem. Management P-Guide") to control memory management (rather than the, "Garbage collection" system)?

Well, the default setting from the SC templates has GC set to "Unsupported". Mark would have to weigh in on that, but I have a feeling that there may be some problems enabling it. Maybe not. Not sure.

SCParamBlock works within an NSAutoreleasePool, which releases on the way out of the external, so I just run with that, autoreleasing objects that I specifically alloc/init. I'm sure I'll find later on that I need to fine tune my stuff some (maybe finding things that I should be setting to autorelease that's not so obvious).
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon


Return to Xcode and the Internals Toolbox

Who is online

Users browsing this forum: No registered users and 1 guest

cron