Slashdot Mirror


Xcode Update Gives Objective-C Garbage Collection

William Henderson writes "That's right, if you haven't read it for yourself yet, Objective-C '2.0' now supports garbage collection. I foresee a great, huge, gigantic debate about to ensue, and a lot of java-heads sparking 'I told you so'. Why not start it here on slashdot?"

42 of 285 comments (clear)

  1. Here's my contribution to the debate. by mccalli · · Score: 4, Insightful
    Fantastic.

    I really do feel that manual memory management in most apps is now redundant. i fully accept its need in some cases an indeed I've advocated 'regressing' an app at work, which was ported from C to Java, back into C again to use manual memory management for performance. But that app's an exception - sub-millisecond performance is required. How many day to day apps need that?

    I can feel myself waiting a few months, then ordering an updated Objective C coding book to pick this language up now.

    Cheers,
    Ian

    1. Re:Here's my contribution to the debate. by Rakshasa+Taisab · · Score: 2, Informative

      On the other hand, I feel automatic memory management is redundant in most situations. Warm fuzzy kind of feelings.

      --
      - These characters were randomly selected.
    2. Re:Here's my contribution to the debate. by mccalli · · Score: 2, Informative
      OK - here's a comparison. App is a multi-threaded market data-driven app. Server-side, so no GUI. Uses around a gig to gig-and-a-half of RAM. Idea is to read in market data, process and response to it in sub-millisecond time.

      "Stop the world" garbage collection for this app usually takes less than 13ms. And it very rarely occurs - you can code appropriately for a garbage collector too, and minimise it ever reaching this level. Usual GC times is between There isn't a human alive that could interact with a GUI in 13ms. So no, you need sub-millisecond performance 'every time you need to interact with a user' is not actually true.

      Cheers,
      Ian

    3. Re:Here's my contribution to the debate. by Glock27 · · Score: 2, Informative
      I really do feel that manual memory management in most apps is now redundant. i fully accept its need in some cases an indeed I've advocated 'regressing' an app at work, which was ported from C to Java, back into C again to use manual memory management for performance. But that app's an exception - sub-millisecond performance is required. How many day to day apps need that?

      Bad idea if you're doing heap allocation in a time-critical code section. Heap allocation ala 'malloc' isn't deterministic, it can take significant time if there's heap fragmentation.

      Better to pre-allocate everything before going into the time-critical part. In which case GC is fine. ;-)

      --
      Galileo: "The Earth revolves around the Sun!"
      Score: -1 100% Flamebait
  2. In response to the naysayers... by Hootenanny · · Score: 5, Informative

    AFAIK, garbage collection may be enabled or disabled as a compiler option. If you don't like it, then just disable it and carry on.

    1. Re:In response to the naysayers... by cnettel · · Score: 2, Insightful

      For now, but it seems to me that interoperability with a library that used garbage collection would require you to use it as well, or suffer some real pain while trying to work out the memory ownership semantics of a library that simply wasn't designed in those terms.

  3. Technical details needed! by Anonymous Coward · · Score: 3, Insightful

    We developers will need far more technical details before we can even consider using this functionality in our applications.

    What garbage collection technique is used here? How does it differ from the Boehm GC-based technique offered by the GCC Objective-C compiler?

    Are any guarantees given with regards to the performance of the collector? Does it suffer from many of the problems that plagued the Java GC?

    What sort of modifications do we have to make in order to take advantage of this support?

  4. Re:uh, neat.... by ronanbear · · Score: 2, Insightful
    I'm quite happy that many programmers will be spending their time on application design rather than debugging memory leaks. Sure there are those out there with years of C experience who don't need this feature and I'm happy for them. They can continue to code the way they always have and they'll still be in demand. But there's another group who will find this really useful.

    At the end of the day Apple aren't really catering for the top programmers here who will write good programs no matter what. It'll help the rest write better programs though.

    --
    the more they over-think the plumbing the easier it is to stop up the pipe
  5. And Leopard has DTrace by SuperKendall · · Score: 4, Interesting

    Far more exciting is that Leopard gets DTrace. Look at the last line of the page the story links to.

    Well, let's say as exciting.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  6. Not sure if you're joking, but... by Space+cowboy · · Score: 3, Informative

    An autorelease pool is a promise that when the pool is released, any objects with a retain-count of 1 will be released. So, you create your objects and call the autorelease method on them:

              NSAutoreleasePool *pool = [NSAutoreleasePool new];
              NSObject *myObject = [[NSobject new] autorelease];

    All that happens is that the object is added to an internal array, and when the pool itself is released, it calls [release] on all the objects in the array. I guess it actually calls [release] on the object as soon as it's gone into the array as well, or the object's retain count would be 2 when the pool was released (one for the 'new', one for the insert-into-array). So,

            [pool release] ... clears up after you, but it's no garbage collection, it's just a convenient way of using retain/release.

    ObjC 2.0 does real garbage collection, like java's. No retain, no release - just automatic management when objects fall out of context.

    Simon

    --
    Physicists get Hadrons!
  7. Re:uh, neat.... by jfengel · · Score: 5, Insightful

    It isn't even a question of how good a programmer you are. It's a question of how good a programmer everybody on the team is. And "team" includes every library you use.

    When memory is passed across the boundary from one developer to another, you need some kind of mechanism to track who is going to free that memory, and under what circumstances.

    Garbage-collected languages make that contract fairly clear. (But not infinitely clear; there are still ways to accidentally pin objects in memory even in a GC language).

    In C we got used to putting in comments saying, "I'm passing you back a static structure, so I'm not re-entrant" or "This thing is malloc'ed so free it when you're done" or "You have to pass in a reference to that object and I'll fill it in". As long as discipline is followed the program works brilliantly (no GC overhead) but if any developer anywhere on the project misreads any single one of those comments, you're completely and totally doomed.

    There is still software to be cranked out by one guy who can keep the entire thing in his head, but software requirements for most things are too big for just one guy. Even the uberest of uber-hackers is limited by the dumbest guy on his team, especialyl when that dumbest guy (even if he's pretty damn smart) nulls out a memory location that wasn't finished yet.

  8. Re:Hacks and Novices Rejoice! by profet · · Score: 3, Funny

    "Garbage Collection is cool cuz you don't have to, like, remember to delete stuff"

    Shudder.

    posted wirelessly via abacus and smoke signals

  9. Your knowledge of GC is 10 years out of date by jbellis · · Score: 3, Insightful

    Modern GC is *faster* than hand-coded free calls in 90% of situations.

    "A major reason for this is that the garbage collector allows the runtime system to amortize allocation and deallocation operations in a potentially advantageous fashion." -- http://en.wikipedia.org/wiki/Garbage_collection_(c omputer_science)

    --
    Carnage Blender : Meet interesting people. Kill them.

    1. Re:Your knowledge of GC is 10 years out of date by cnettel · · Score: 2, Insightful
      True. The most adverse effect of Java-like GCing is not the allocation method, it's the amount of allocations, and the references to wherever and whatever all the time. In C/C++, you can really store a string locally with an object. If you do it smart, you can even allocate the memory for several strings with dynamic size and still have guaranteed locality and a single heap allocation. In Java (or C#), you're almost bound to have several references, each with a separate vtable reference and so on. Structs in C# is a step in the right direction here, because they remove a tiny bit of the paradox that you have to choose between a nice OO representation or roll your own memory manager with no other primitives than, essentially, bytes.

      And, to some degree, GC is responsible for the fact that it's impossible to do nice data structures on your own, as a GC needs to be able to track and relocate references. To do that, it has to grok your data structure.

    2. Re:Your knowledge of GC is 10 years out of date by CoughDropAddict · · Score: 3, Interesting

      Modern GC is *faster* than hand-coded free calls in 90% of situations.

      Greater throughput at the expense of latency. GC stops the world.

      "A major reason for this is that the garbage collector allows the runtime system to amortize allocation and deallocation operations in a potentially advantageous fashion."

      I would like to offer you a bank account with 50% interest amortized over 500 years. I regret that you will not receive your first interest payment until the 500 years are up.

      The point is that amortized performance gives you no control over when you're going to take the hit. That's OK if you only care about throughput.

    3. Re:Your knowledge of GC is 10 years out of date by feijai · · Score: 2, Interesting
      The most adverse effect of Java-like GCing is not the allocation method, it's the amount of allocations
      A modern Java virtual machine uses a compacting GC. This allows it to perform the following super-duper, evil, highly intensive allocation procedure for an object of N bytes:
      1. Increment the heap pointer by N.
      2. Bzero those N bytes (if necessary).
      3. Return the old heap pointer.
      In what way exactly is this more expensive than malloc? That's right, it's far less expensive than malloc. It's just as expensive as stack allocation in fact.

      Where GC falls down is in the (slight) cost of deallocation of those tiny, short-lived objects and in not being able to take advantage of cache coherency for short-lived objects well -- though it's great for long-lived objects and caches. But virtual machine techniques are improving every day. Soon we'll have object analysis in most VMs to determine if objects can be stack allocated or not.

  10. Re:Hacks and Novices Rejoice! by kaffiene · · Score: 2, Insightful

    *sigh*

    I grew up programming in assembler and C. Even dinosaurs like myself know that memory allocation is not an issue for 99% of software projects.

    Get with the new century dude.

  11. Re:Why not Objective C? by JulesLt · · Score: 2, Interesting

    >I'd like to know why isn't ObjC more popular outside Apple (and NeXT) circles

    Because it's 'a failed language'. If they could come up with a rebrand (AJAX) or take the concepts and give it a syntactic revamp (maybe based round Ruby) they'd be well away, but the predominant line has been C to C++ to Java (and now C-sharp) - and only recently have Java developers begun to demand the features of a true OO language.

    To be fair, there were good performance reasons why C++ won over Smalltalk regardless of it's productivity benefits, but these have become less and less important for UI bound programs.

    --
    'Capitalists of the world, unite! Oh ... you have' (League Against Tedium)
  12. NOOOOOOO #@$#$@ by pestilence669 · · Score: 3, Insightful

    Objective C has one of the most elegant reference counting implementations on the planet. Virtually no thinking at all is required to manage memory. Cyclical relationships, which shouldn't exist in decent code, are its only limitation. It's also very fast. Anyone who argues that memory management in Objective C is difficult, should have their head examined.

    Garbage collection is a step backward, IMO, but every language seems to be moving in this direction. I really do believe that resource awareness is crucial to efficient programming. Garbage collection encourages lazy programming habits, which I've seen in quite a few Java developers. Bad habits, once bred, are hard to get rid of.

    Now, instead of profiling memory for leaks, you can profile the garbage collector, which I predict will be just as much of a headache as tracking down a memory leak. In the end, little work is saved, at least from my experience debugging other developers' Java applications. I won't know for sure until I play with XCode 3.

    1. Re:NOOOOOOO #@$#$@ by pikine · · Score: 3, Interesting
      Objective C has one of the most elegant reference counting implementations on the planet.

      There is no need to panic. You can support both reference counting and garbage collection in one run-time, provided the objects are in separate heaps. Whenever there is a reference from reference counting heap to the garbage collected heap, you simply tell the GC that there is a "root" reference inside a reference counting object. The other direction is probably even easier. A conservative GC can discern whether a reference is managed by the GC or not. Otherwise, we can foil a GC's attempt at traversing outside of the GC heap by marking a reference as an integer or by wrapping it in a special binary object that GC does not traverse.

      Now, instead of profiling memory for leaks, you can profile the garbage collector, which I predict will be just as much of a headache as tracking down a memory leak.

      Ever heard of suggestions that global variables are harmful? This is even truer for GC memory management. These globals have roots that persist throughout the lifetime of a program. For this reason, Java programmers seem to suffer more GC problems than a functional language programmer. In fact, the only place you need to look at, in the case of a "GC memory leak," is your global variables.

      Unless a GC implementation is flawed, GC does not produce memory leaks. The leaks you are talking about are still technically used by the program but the programmer is not aware of it.

      Debugging reference counting is just as much work as debugging malloc/free. In both cases, you need a map tracking the creation, duplication, and consumption of references.

      Garbage collection is a step backward, IMO, but every language seems to be moving in this direction. I really do believe that resource awareness is crucial to efficient programming.

      If by efficient programming you also take into account run-time overhead, some implementation of GC is more efficient than some implementation of malloc/free. For example, a copying GC only maintains a "heap top" pointer, and any new object is allocated from heap top only. In contrast to malloc/free implemented as linked list traversal, GC takes O(1) time to allocate, and O(n) time when it runs out of memory; malloc/free always takes O(n) time.

      I'm sure other people will fill in the details here if they want to. The point here is that you cannot compare blanket GC with blanket reference counting or malloc/free.

      If by efficient programming you mean the time it takes to write code, I believe GC is the winner here, since you forget you're using memory altogether.

      --
      I once had a signature.
    2. Re:NOOOOOOO #@$#$@ by m874t232 · · Score: 4, Insightful

      You're missing the point of garbage collection. Garbage collection isn't there to save your effort. In fact, garbage collection does not save you effort at all. The purpose of garbage collection is to make the language safe and isolate errors, something that no other storage management scheme can achieve.

      Both manual storage management and garbage collection each require a lot of experience to use correctly. Your problem is likely that you underestimate both how much work it took to become proficient at manual storage management/reference counting, and how much work it would take you to become proficient in a garbage collected environment.

    3. Re:NOOOOOOO #@$#$@ by shobadobs · · Score: 2, Funny

      In contrast to malloc/free implemented as linked list traversal, GC takes O(1) time to allocate, and O(n) time when it runs out of memory; malloc/free always takes O(n) time.

      First of all, even dumb mallocs do not 'always' take O(n) time.
      And comparing GC to a craptardic mallocation strategy is like comparing any sorting algorithm against bubble sort.

    4. Re:NOOOOOOO #@$#$@ by bar-agent · · Score: 4, Informative

      Objective C has one of the most elegant reference counting implementations on the planet. Virtually no thinking at all is required to manage memory.

      Oh, is that why the Cocoa-Dev mailing list has a brand-new reference counting question every damn day? It is clearly not as simple as you think.

      --
      i'd hit it so hard, if you pulled me out you'd be the king of britain [bash.org]
    5. Re:NOOOOOOO #@$#$@ by Abcd1234 · · Score: 2, Interesting

      Well, first off, Java doesn't have closures. It has anonymous inner classes which maintain a reference to their containing class, and can access it's member variables, but that's definitely not a closure. Though, I sure wish it did... I tend to program in a functional style, and I've lamented the lack of lexical closures in Java on a number of occasions.

      Secondly, I challenge you to describe a situation in which you can leak memory in Java despite throwing away the reference to the object in question. I'm willing to bet you can't.

    6. Re:NOOOOOOO #@$#$@ by m874t232 · · Score: 2, Insightful

      I detest it when a GUI pauses for no good reason,

      And I detest it when a GUI pauses for no good reason, just because the manual storage allocator has needlessly held on to extra storage and the application is now forced to go to virtual memory.

      Garbage collection can also lead to unpredictability.

      There are different kinds of garbage collectors: some are intended for non-interactive programs and minimize long-term CPU overhead, while others give guaranteed real-time performance. There's also a middle ground of "near real-time" performance.

      Furthermore, even with a non-real-time garbage collector, you can achieve real-time responsiveness if you know what you're doing. Of course, your comments suggests that you wouldn't know how, which is why you prefer sticking with manual storage mangaement.

      Don't be a programmer-bureaucrat; someone who substitutes marketing buzzwords and software bloat for verifiable improvements.

      Take your own advice to heart and try to actually verify your claims about manual storage management and garbage collectors; you'll be surprised.

    7. Re:NOOOOOOO #@$#$@ by grammar+fascist · · Score: 3, Insightful
      Garbage collection is a step backward, IMO, but every language seems to be moving in this direction. I really do believe that resource awareness is crucial to efficient programming. Garbage collection encourages lazy programming habits, which I've seen in quite a few Java developers. Bad habits, once bred, are hard to get rid of.

      You're missing the point, which is to make it easier to model a language mathematically. The easier the model is to reason with, the fewer errors you'll have. It frees your mind from petty concerns that arise from having an overly-complex language model.

      We'll go back to Lisp to elucidate this, which has always cleaned up after itself. Lisp has a very strict underlying mathematical model. Consider math for a moment. Once you define something, is it ever undefined? If you've stated a truth, is it ever not true?

      No. Likewise, in languages with garbage collection, once you create something, it exists, theoretically, forever. In the theoretical language model, memory is infinite. The fact that something cleans up stuff that isn't referenced because we happen to be using state machines rather than true Turing machines and need the memory back is merely a necessity of living in the real world.

      There's a beauty and an elegance about "garbage collection" (i.e. the more-mathematical infinite memory model) that you're totally missing out on.

      Mathematically speaking, mutable variables are a bad habit. As you say, bad habits, once bred, are hard to get rid of. Can you break this one? You don't have to, just think about it. The point is, I'm challenging you to expand your mind a bit and understand that what you hold dear isn't all there is in the world of programming.

      Cyclical relationships, which shouldn't exist in decent code...

      Where did this piece of utter tripe come from? Haven't you ever created a circularly-linked list? Must everything in memory be a tree?
      --
      I got my Linux laptop at System76.
    8. Re:NOOOOOOO #@$#$@ by ysachlandil · · Score: 2, Informative

      >It's also very fast

      -sarcasm on-
      Excuse me? A reference counting implementation that is fast. Could you please post some links to articles describing this magical algorithm?
      -sarcasm off-

      Mark-and-sweep GC or copying GC is _always_ faster than doing reference counting.

      references:
      http://www.hpl.hp.com/personal/Hans_Boehm/gc/issue s.html
      http://www.cs.umass.edu/~emery/pubs/gcvsmalloc.pdf
      http://en.wikipedia.org/wiki/Reference_counting

      --Blerik

  13. Re:why is it.... by JulesLt · · Score: 2, Interesting

    What's the new architecture it runs on?

    As far as I can see it's still a Cocoa app, so while it's certainly possible (we know the Next frameworks would run on top of multiple kernels) it is unlikely unless Apple decided to open up the layers above Darwin (unlikely). Alternatively, resource could be put into the GnuStep project, but overall there seems very little interest in it. (The non-Apple Obj-C community is tiny).

    DTrace is currently only on Solaris and BSD (at least last I knew).

    I'd imagine there would be more hope in a project to add similar features to Eclipse, where you may at least encounter a pool of developer motivation (including Mac developers who don't want to work with XCode).

    --
    'Capitalists of the world, unite! Oh ... you have' (League Against Tedium)
  14. Garbage Collection and Apple by beswicks · · Score: 2, Interesting

    Let me be the first to welcome our new garbage collecting Overlords.

    I love Objective-C and Apple (NeXT) API's. However, while garbage collection does make it "easier" to write software, I have GREAT fears about people not leaning to clean up after themselves.

    Case in point was a University project I did involving robots. Everyone happy sets about coding there little robots in Java, write some simulators, then write the actual robots logic, all in wonderful cross platform Java. Que 100 students pondering why real thing ran for 20seconds then started beeping at them. I spent a LONG time trying to explain to people that with 64k of memory, and NO garbage collection (yey "special" Java) you cannot just keep creating temporary objects at will and hoping mummy will clean up.

    I think its super that Apple will be even easier to write for, but please make sure your know how to clean up after yourself before you start coding, you never know when silicon mummy will be on holiday.

    NB. Not sure I mean "easier" to write software, maybe "allows you to write with a little more of your brain unplugged".

  15. Apple innovates... by cortana · · Score: 2, Funny
    -lgc
    I kid, I kid! :)
  16. Re:Yay! More Bloated Crappy Code by Maury+Markowitz · · Score: 3, Insightful

    Practically every program I run under XP has a memory leak. As a result, quitting out of any of then leads to 15-20 seconds (yes, really) of disk griding while the VM dies. And this is on *quitting*. Does anyone else find it the least ironic that it takes longer to quit a program than start it?

    I love listening to people complain about GC. Of course *they* are super-programmers that don't need any of this stuff, because their code never has *any* problems in it. But here I am with all these leaky programs. They leak memory all over the place and don't care. Why? Because I don't *need* to care about memory, everyone has 1GB anyway.

  17. Re:uh, neat.... by pestilence669 · · Score: 2, Informative

    Yes, but in Objective C there ARE standards for who frees memory. Whomever allocates an object must free it. This seemingly difficult methodology is accomplished with auto_release pools. When you return a new instance of an object, you send it a release message, which adds it to the auto release pool. Once your event loop is complete, every object in the pool is destroyed. If the recipient wants to keep a returned object around for a little bit longer, it sends it a retain message, which removes it from the pool. In practice, this method is exceptionally simple to use. The overhead is larger than manual destruction, but much less than garbage collection. Autorelease pools are great because object destruction is delayed until the next event loop iteration. This means that lazy access to the object, immediately after release, will work without penalty.

  18. many people miss the point of GC by m874t232 · · Score: 2, Insightful

    Many people think that the purpose of garbage collection is to make programming easier. But that's not the purpose of garbage collection at all. Memory management in a garbage collected language is at least as much effort as memory management in a language with manual storage management, and it requires at least as much experience to use well.

    The purpose of garbage collection is to make languages safer. If Objective C 2.0 has additional features to make it safer (variable initialization, pointer checks, etc.), then garbage collection will help it. Otherwise, it's just a gimmick.

    Unfortunately, from Apple's web page, it's difficult to see what exactly they did; adding garbage collection to Objective C in a useful and correct way is a nearly intractable problem, and I won't believe that they succeeded until I see more data.

  19. Oh dear, where to start ? by Space+cowboy · · Score: 4, Informative
    • Because it can be a lot slower than C++.
      Well, actually if you really *need* speed, then ObjC groks C perfectly - it's a cast-iron guarantee that any legal C will work in objC, unlike C++. C performance is just as good as C++...

    • C++ gives you control over the object messasing system whereas Objective-C uses virtual methods for pretty much everything and there is nothing you can do about it.
      Um, no. Objective C uses dynamic despatch (ie: the method to run is determined at runtime not compile-time. This is one of its most powerful features. As for "nothing you can do", you can retrieve the bound method as an IMP (like a function pointer) and call it directly to remove any overhead. Useful in loops.

    • Objective-C is actually a lot like COM which is Microsoft's object extension for C. It was designed about the same time with many of the same goals. Both basically came about because of the incredibly slow progress C++ was making at the time.
      No. Objective C was designed as an adaption of the ideas behind smalltalk, as applied to C. It was designed in the early 1980's, COM was designed in 1993, although it wasn't called COM until 1997.

    • Objective-C has no template system. This is a huge advantage for C++.
      Well, that's a matter of opinion, but in any case, Objective C is a dynamic language. Most of the power of templates is encapsulated within the dynamic-despatch abilities of the language, coupled with the 'protocol' feature of the language.

      It could be said that Objective-C is a lot like Java with many of the same problems but because it was never marketed with a cross-platform VM it didn't take off like Java.
      I think it is significantly like java, but it's compiled (like C/C++). It's a *lot* faster than Java, and handily beats gcj too, at least on the tests I've done. You need to enumerate these "same problems" before I can respond though.

    • Overall C++ is more C-like than Objective-C. That is it gives you much more control over the exact level of performance versus ease-of-use that you want
      Um, take any legal C code and it *might* compile in C++. It *will* compile in ObjC - how can C++ be "more like C" than ObjC ?

    ObjC has introspection, dynamic binding, (now) optional garbage collection, (always) a very easy retain-count allocation system, really easy-to-learn constructs (I think there's 12 new statements, or something like that), *and* a weird syntax - it grows on you though :-) It actually does surprise me that more people don't like it. If Macs get more popular, who knows, perhaps it will have its day in the sun...

    You need to read the PDF manual. There's a lot of stuff you're saying as fact, that is simply wrong.

    Simon
    --
    Physicists get Hadrons!
  20. Re:Why not Objective C? by Novajo · · Score: 4, Interesting

    Objective-C has no template system. This is a huge advantage for C++.



    This is interesting because C++ has templates only because it needs them and Objective-C doesn't have them because there is no need. For instance, you can't have a C++ array of "anything", unless all objects descend from the same class, and then you are restricted to functions that were declared in that base class. That's because C++ is statically typed and needs to know the virtual table to use for the function call (whatever the function is). On the other hand, Objective-C does not need templates because function calls are not looked up through a virtual table, they are dynamically sent as messages, which are handled if the object implements that function. Hence, you can (and do) have a general-purpose array in Objective-C. You can even have a general purpose hash table with changing element types...! I'd love to see an implementation in C++ that is readable.


    The "Object Penalty" (i.e. the cost of using a certain object-oriented language) is fixed, and it therefore reduces over time with faster and faster computers. C++ will do anything to make that cost as small as possible, including getting in your way. So really, the advantages of C++ are decreasing over time if you consider all the hoops you have to jump through to get what you want. When you really need performance in Objective-C, you write that little snippet of code in straight C (just like everyone else does in C++ .)


    I was a C++ junkie for 10 years until I tried Objective-C and quickly noticed how much more complex a task I could handle without the language getting in my way. You should try it.

  21. Re:Specifics please? by squiggleslash · · Score: 2, Insightful

    I think the "problems" are the elitist programmers who haven't realised yet that they actually aren't perfect... ;-)

    Ooohh! Ooooh! -5 Flamebait! Go on, I dare you!

    Seriously though, the major problem is that Java's advantages are rarely what the loudest advocates suggest. They'll talk incessantly about how they were able to get their app out in Java in only six weeks, and that it's all about making the programmer's life easier. That's not really it. What Java does is trap more errors, and moves from an insanity (manual memory management) to a more natural, free flowing, yet structured, memory model (at the end of the day, it's not even about garbage collection, that's just a side benefit of the memory model). And moreover, it prevents programmers from making common mistakes. And some programmers think that they are good enough to avoid those mistakes. But, you know what? I seriously doubt that. And I'm sometimes the guy who's running your program. And I don't trust you. You trust you. I don't. I'm being asked to trust you when I run your software, or when I add your software to mine, and I'd rather not. Not because I'm being insulting, or hate you, or anything like that, I'm just realistic. Even Knuth has had a few bugs to fix in TeX.

    Java doesn't guarantee correctness, but it catches more bugs, and it makes some of the more dangerous ones - the buffer overflows, the stack overflows, etc, etc - practically impossible. I'd be curious to know if Objective C does the same thing, or if the obsession with the GC aspect of Java has gotten the better of everyone, again.

    --
    You are not alone. This is not normal. None of this is normal.
  22. ObjC Referencing Counting In A Nutshell by Anonymous Coward · · Score: 3, Informative

    The entire scheme is lexical. If you do a [obj retain] you are responsible for doing the [obj release]. So,

    [[NSMutableArray alloc] init]

    will require you to release the array object, but

    [NSMutableArray array]

    won't. Objects added to autorelease pools are automatically released at the end of each runloop. It's a convenience thing... so instead of doing:

    NSMutableArray *ary = [[NSMutableArray alloc] init];
    [someObject setValue:ary forKey:@"someKey"];
    [ary release];

    you can do either [[[NSMutableArray alloc] init] autorelease] or [NSMutableArray array] (which does exactly the same thing) and drop the release. Voila! One whole line of code saved/invested. Also you can use ObjectAlloc (from a menu in Xcode) to see stacks of everything that has been allocated.

    Having said all of that, memory management is tricky in Cocoa because *everything* is tricky in Cocoa. Lots of entry/exit points in the code which can make it difficult to determine where a problem occurs even w/ NSZombie's and a nice stack trace. Complicated user paradigms, i.e. cut & paste and undo & redo.

    That's not a complaint, just a statement. More options = better.

  23. Re:Hacks and Novices Rejoice! by kaffiene · · Score: 2, Interesting

    This isn't a C versus Java discussion - it's Objective-C versus Objective-C with GC discussion, so your point is completely irrelevant as both OC with and without GC have stack allocation.

    That said, *yes* stack variables allow a certain amount of programmer optimisation not explictly available to Java programmers, *but* that is all optimisation that the JVM can do via escape analysis (but you knew that, didn't you?). What's more, that kind of analysis can allow a JVM to optimise values onto the stack depending on usage - something not at all possible with C's ahead-of-time compiler.

  24. Re:Sonny, since the effect is the same by Abcd1234 · · Score: 2, Interesting

    Uhh, the effect isn't the same. A memory leak results in memory regions that are no longer available to the program, because the reference to the original region is gone. Thus, the memory can no longer be reclaimed. Clearly, that's not the case in the situation you described. You said yourself that the GC eventually reclaimed the memory... it just didn't do it when you wanted.

    Oh, and BTW, your use of "sonny" is unsurprising, given your last experience with the Java GC was version 1.2. Maybe try updating your experiences and try again.

  25. Re:Why not Objective C? by powerlord · · Score: 2, Informative

    Oddly your description of Objective-C resonates with descriptions of Perl I have read. :)

    I'm going to have to take a look at it.

    --
    This space for rent. All reasonable inquiries will be entertained at proprietors discretion.
  26. Re:Great..now to persuade those C++ hotheads! by Bill+Dog · · Score: 2, Funny

    As a C++ hothead, I think it would be great if GC was added to C++, contingent of course on it being added according to the spirit of C++, which is you don't pay for what you don't use. I.e. make it available as an option in the language, but not always activated. I'll also add, C++ programmers are used to and favor deterministic destruction, so a GC for C++ should be able to be triggered, and the language should specify that it doesn't return until all objects that could be freed at that point are. We like control, and guarantees. If it were implemented that way, I might even use it.

    --
    Attention zealots and haters: 00100 00100
  27. Re:Library only GC by Haeleth · · Score: 2, Informative

    The library is compiled with GC on, so when the method returns the object, the object is registered with the GC to be watched for its reference count going to zero, for example. Now you don't wish to use GC in your own code, so you compile with it off. Then the compiler will never add the code to effect decrementing the reference count in the GC's tables, so the object will never be GC'ed.

    You're right that mixing GC'd libraries with non-GC'd libraries would probably be a Bad Thing, but your idea of how a GC might be implemented is curious. I can think of few systems likely to perform worse than one based on a global table holding reference counts, thus combining all the disadvantages of reference counting (decreased performance due to the need to update reference counts constantly and atomically, inability to handle cyclic data structures) with a massive loss of memory locality (hello, cache misses galore!).

    Perhaps you should go and read up on how GC works. You might find it interesting. :)