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?"
"Garbage Collection is cool cuz you don't have to, like, remember to delete stuff"
Shudder.
But it's about time if you ask me!
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
Well, let me be the first to enter the, "Guess I'm not using Objective-C" camp. Adding garbage collecting to this language is just a continuation of the "throw more resources at it and it'll all work just fine" mentality that exists in modern application design. Yes, the ease of use of garbage collecting has it's uses for the quick fire and forget projects and one time use apps. But other than that, bah I say!
I'm confused... I thought that ObjC did have garbage collection...
isn't that what the Autorelease pool is for? or is this more automatic?
...spike
Ewwwwww, coconut...
If people like you were in charge of innovation, we'd all be running Commodore 64s with hacked CP/M.
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.
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?
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
... that this is under it.slashdot.org? shouldn't this be under apple.slashdot.org?
that aside, given the new architecture xcode runs on, is there a way to get an x86 port for linux of xcode?
I am very curious about what XCode 3.0 entails in general, but cannot find much information about it. Is there complete coverage somewhere?
Apple seriously needs to get on modernizing their tools. XCode was great when it came out, but it's now years later and their current tools look archaic next to the competition, and until now Objective-C hasn't been updated since like 1985.
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:
... clears up after you, but it's no garbage collection, it's just a convenient way of using retain/release.
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]
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!
From what I understand it's a minimal OO extension of ANSI C, that is easier than C++ to learn and easier to compile. The addition of native garbage collection to the std lib could offer huge gains in development time. I'd like to know why isn't ObjC more popular outside Apple (and NeXT) circles?
Only folks attending WWDC have the XCode 3.0 pre-release. They're all covered by a Non-Disclosure Agreement, so they can't (legally) say anything about it. Some information will doubtless leak out, but you won't see anything like a full review of it until it ships (presumably with Leopard).
There's a few additional details and a screenshot up on Apple's site:
http://www.apple.com/macosx/leopard/xcode.html
-Mark
Does this mean I need buy all new $50 USD books to understand this new technology?
That's my main computer you insensitive clod!
Yay, another tool which encourages people to create bloated, flaky code.
-I don't *need* to care about memory, everyone has 1GB anyway
-I don't *need* to perform analysis on the algorithm, the garbage collector will take care of it *for me*.
-I don't *need* to do performance analysis of my code, since the randomness of the garbage collection algo will make any results totally meaningless anyway.
This is why there are still classical OO languages, ala C++, which are for real programmers and REAL software engineers to use. Let the code monkeys deal with Java and the like.
Modern GC is *faster* than hand-coded free calls in 90% of situations.
c omputer_science)
"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_(
--
Carnage Blender : Meet interesting people. Kill them.
and your point is?????
'...if only "Jumping to a Conclusion" was an event in the Olympics.'
The marketing-fluff webpage linked to talks about stepping back during a debugging session - is this for Objective-C only or is it available for every language? Now that is a compelling reason to upgrade
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.
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".
I think we really have to accept and embrace real innovations to productivity. Things such as compilers, optimizers, high level interfaces, has brought us great benefit. If we look at it in real terms the advancements are awesome. In the Mythical Man Month I seem to recall that coding speeds were cited as dozens of lines per day. Compare that to what we can do now. The down side is that we perhaps waste resources, and in many ways the computer industry is crushing itself under the weight of wasted resources, but that is merely another management issue.
"She's a scientist and a lesbian. She's not going to let it slide." Orphan Black
I loathe /. cliches as much as the next person, but "Garbage Collecting Overlords" definitely deserves a point or two.
I have been a Java developer for eight years. What problems have plagued Java garbage collection?
Join Tor today!
I've started to notice that there are /. stories that I miss because they don't appear in the RSS feed. What's going on?
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.
It seems to me that since it is a compiler option that if a library required it, it would be compiled to do so and you could simply use it from your non-GC code directly. It's not like Objective-C is suddenly running in a VM, the compiler is adding code to effect the GC.
"There is more worth loving than we have strength to love." - Brian Jay Stanley
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++...
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.
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.
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.
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
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!
As a good programmer, it is a sane practice to check your app under some sort of leak detector. These things make it very easy to spot and fix memory leaks under various test cases. It does not take a "super programmer" to remove 99% of memory leaks in a fairly complex program.
I assume you are talking about a server machine. I was just wondering, how many CPUs does it have, as well as the CPU cache size. Server machines != typical desktop intel box.
That's why garbage collection is so popular. Even if it's not your code, it could always be your co-workers code (added in a hurry under a tight deadline), or some proprietary 3rd party library kept on life support via the lowest offshore bidder (which you still pay full US sales & marketing Lexus buying price for). In those cases, give me a GC platform any day. Because the people who will be screaming for your head on a platter don't care who's fault it is for not cleaning up, and you have better things to do (like solve their problems and make working software) in the 1st place...
*** Sigs are a stupid waste of bandwidth.
For years there has been speculation that Apple would add support for Java-style messaging syntax to Objective-C.
Objective-C uses a Smalltalk-like syntax when sending a message to an object:
eg. [object messageName:arg1 furtherMessageName:arg2];
Java, on the other hand, uses a syntax derived from C++:
eg. object.messageNameFurtherMessageName(arg1, arg2);
Will "Objective-C 2.0" offer support for the Java-style syntax?
Anything in the autorelease pool with a retain count of *zero* is automatically freed on the next invocation of the main event loop.
In other words, I don't know what this "real" garbage collection brings to the party.
Clear, Dark Skies
I can feel myself waiting a few months, then ordering an updated Objective C coding book to pick this language up now.
I might consider it, too, if I hadn't discovered the D programming language. I can't do a proper comparison because I discovered D shortly after I started experimenting with Obj-C and lost all interest in the latter and no longer remember much about it except that it belonged to the "fast, not convenient" camp, like C and C++.
D was designed from the ground up as a memory managed Super C. The intention was to provide both the power of C and the convenience features of today's most popular scripting languages in a natively-compiled C-like language, with a host of other modern features such as full-fledged Eiffel-style design by contract, native Unicode strings, real arrays, etc. In order to offer as much of C's power as possible, it lets you manually override the memory management where you want to.
I'm not sure what's going on with D at the moment, though. The forums stopped working a few weeks ago, and today the whole website (digitalmars.com) seems to have gone offline. I hope everything is okay....
"Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
The garbage collection mechanism by Hans Boehm has been available in GNU GCC for C, C++ and, yes, it also works for ObjC, for quite a while. And the big deal about this being added to Apple's implemnentation of ObjC is?
The "big deal" regarding ObjC 2.0 is the syntax "enhancements" I'll bet. So far, I haven't seen any examples of "ObjC 2.0" code.
GJC
Gregory Casamento
## Chief Maintainer for GNUstep
It would be interesting, I agree with that. But John Carmack didn't write Quake 3 in Objective-C. He used a black-and-white NeXTstation during the development of the original DOOM, but that game and every game until DOOM 3 were actually written in C (and some assembly, presumably). All of the tools for these games were originally developed in Objective-C, because NeXTstep (and by extension, Cocoa) is a fantastic development system for that sort of thing. That's why there were no official tool releases for DOOM and Quake: Not enough people had a NeXT system to run it on so it wasn't worth it.
I think around Quake 2 or Quake 3 Arena they switched to Windows as their primary development platform. Carmack started writing his tools in C++ (again, I think), and eventually the game (DOOM 3) as well. But none of the Id games were written in Objective-C, just the tools. I'm sure John Carmack would have many nice things to say about Objective-C though, since he held on to his NeXT environment for a pretty long time.
Garbage collection is only one part of what makes a language like Java safe, and Objective-C doesn't have any of the other parts. Unless they plan to also implement array bounds checking and restrict pointer casts and arithmetic, this new Objective-C will happily stomp all over your garbage-collected memory, producing bugs just as weird and security holes just as bad as before. Without the full safety package, the benefits of garbage collection start to look rather meager if one discounts convenience. Personally I think one shouldn't. Saying garbage collection doesn't save effort is ridiculous. Producing optimized code isn't easier with garbage collection, but producing slow code is. Meaning that the routine majority of your coding gets done sooner and you can focus your effort on the parts that actually need to be fast.
Firebug. It will make your jaw hit the floor.
I got the point about half the mem being actually free (paged out). Thanks, that clears up the issue somewhat.
The point is, before I tried java apps, I was fine on a 256MB system and never needed to enable swap space. So I never did. Then suddenly I got this whooping app loading up all my 512 RAM and then thrashing like hell - so, naturally I said WTF. It is kind of tricky - without swap space that RAM was actually wasted.
D'oh. Thanks for clearing up one misunderstanding about Java. Still, Java GUIs seem kind of slow to respond, compared to native stuff. Oh well.
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.
I see way too many programmers running around, writing the most ineffective code possible, and relying on fast machines to hide the fact that their code uses 1 gig of ram to display "hello world". That being said, I think that programmers should try to strive for the most effective coding strategy possible, simply because it is good practice. You may only have to make small programs for your company now, but in the future you could be making hardware intensive applications, and if that time comes, effective coding strategies need to be implemented. The main problem I think with Java's memory management is that it doesn't let you control enough. It allows the JRE to control too much memory allocation. That is one of the main reasons that people think that Java is slow. I think that adding GC to objective-C will give developers another option to try when tweaking for speed.
Klingon Software is not released, it escapes, inflicting terrible damage onto the enemy as it does
Your signature line has a maximum of 120 characters. It says so right next to the box where you fill it in. Are you some kind of fucking retrad, or are you just retraded? Or maybe you just can'to cunt? Or maybe you don't want to count? Don't bother repsonding to this post, becuse aI won't see it. Didlo.
A vector has _exactly_ the same cost as an array if we ignore the cost of the initial dynamic allocation. Why? Because it's implemented as one on most STL implementations. Any reasonable inlining compiler will turn element accesses into direct array accesses, so no performance is lost there either. I believe TR1 will also add array which does static allocation and allows compile-time references to individual elements.
Btw, templates are used for other things besides generic containers, and can indeed allow greater-than-C-efficiency in some areas. This is because you can encode more semantic information into templates and effectively "program" the code generator to generate better code, especially where cache utilization is concerned -- see Blitz++ for an example. Of course, this is highly non-trivial to do correctly, but for expert programmers templates can indeed be an incredible tool.
Actually I think I am correct - the reason the event loop is important is that it always creates an autorelease pool at the start of the loop, and destroys the pool at the end of the loop
Hrm.
So, I googled around and I see both explanations on the web - the NSAutoReleasePool class seems to do as you describe; yet my developer books and past experience are as I describe - the heap/malloc zone used for default allocations is an "autorelease pool".
Clear, Dark Skies
Although, you still risk chasing an invalid pointer if you hang onto an object after you release it.
If you forget to release, you leak.
GC is unpredictable and has caused huge problems for me when I've worked with Java desktop applications in the past - Java apps ballooning up to large sizes then freezing for several seconds as the GC finally wakes up - it wasn't pretty.
Perhaps things have changed since Java 1.2; but that's certainly been my experience. Besides, scanning every pointer and handle in an application just to see if it still points to something is an awfully ugly hack to get around programmer stupidity.
Clear, Dark Skies
I've been coding C for just under twenty years and I can tell you, you're wrong. Modern GC's allocate faster than C's malloc routine.
If you've been coding for 20 years, but failed to realize that malloc() is not part of C, but part of libc - and varies from OS to OS and from compiler to compiler, then I don't know how I can believe your assertions about performance.
Linux malloc() is based on the glibc and is slightly brain damaged from my point of view, because it can't be properly overridden for debugging or dma operations (it has debug hooks but they aren't thread safe). OS X malloc() is a different implementation that actually supports multiple heaps and allows for the different heaps to have different allocation/release strategies.
There are other algorithms as well, which any book on the subject would tell you.
Clear, Dark Skies
The malloc code in OS X supports what are called "zones" - each zone is it's own heap and function library for managing the heap. They're probably just swapping the default allocator for one that supports GC.
I'm still unsure about the value of this, but I don't think it would require changes to the applications themselves.
Clear, Dark Skies
Garbage collection is truly necessary to write apps effectively and quickly. I admit some types of apps do not need garbage collection...but most of them do.
So let's all sign the following petition, and maybe those C++ hotheads can be persuaded to include garbage petition in C++:
petition for putting GC in C++.
And yet, you are the one claiming that C's malloc is slower. Since malloc isn't a single thing, how can you make that claim?
Clear, Dark Skies
You'd have to provide cites for GC being "often faster". I really can't see how scanning the stack and globals for pointers that might either point to an entity or, worse, to the interior of an entity can be fast.
I spend my days working with code that does lots and lots of pointer math, where the pointers are nowhere near the beginnings of the buffers; I can't see how GC would do anything but accidentally free memory that some DMA operation is still using.
Clear, Dark Skies
It's just that people coming from straight C aren't used to it.
I'll be the first to admit that I've been caught by releasing things early, or worried that I wasn't releasing things that could be - but once you get into the habit of retaining things you want to keep and releasing them when you don't want them anymore it's no harder than malloc and free.
Clear, Dark Skies
The problem isn't Objective C, it's that people choose the wrong language for the job.
I'll be the first to admit that Java is easy to use and has some powerful features. At the same time, I wouldn't write an OS or a device driver in it. Objective C, like C++, was an attempt to retrofit OO features onto a highly machine-oriented language. In the abstract, I think that is a foolish thing to do but, compared with the original C++ grammar, I think ObjC was a better job.
C++ has improved a lot since then, but I still don't think I'd choose to use an OO language for low level work, any more than I'd use straight C to design a web site.
Clear, Dark Skies
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.
So, the GC is a different allocation zone? Do you use the various *withZone functions when allocating for the GC, or does the GC become the default and you use *withZone functions to get the retain release model?
Clear, Dark Skies
Apple has always pushed their ObjC changes back to gnu - but that doesn't mean various users/distros provide a gcc that has those features enabled.
(checking my ubuntu partition...)
Yeah, Ubuntu, at least, includes support for compiling objective C files. I doubt the Ubuntu glibc includes support for retain/release OR this new gcc though. Last time I looked at the source code, the Darwin version of malloc() was utterly different than the generic version. The Darwin version of malloc has some very interesting features; for example, it maintains a sanity-checking system that keeps you from free()-ing memory to a heap that wasn't malloced() from that heap. Those features actually caused me some serious headaches when porting Linux DMA code to Mac, but we were also able to use those features to overcome those headaches.
I have no idea which malloc implementation is faster, but Darwin's generally seems more robust.
Clear, Dark Skies
Obj C is C with some syntax extensions - I'm not trying to pedantic, ObjC code tends to look like a Reese's Peanutbutter cup - there you are, happily eating your chocolate, errr...., reading C code, when suddenly you discover someone mixed some Smalltalk into it.
Clear, Dark Skies
From my 1st edition ADC Cocoa book...
Each application puts in place at least one autorelease pool and can have many more. An autorelease pool tracks objects marked for eventual release and releases them at the appropriate time.
To me that implies that the same pool exists for the life of the app.
Maybe the behavior changed sometime after 10.0?
Clear, Dark Skies
Ummm... In my professional experience with Java, "freeing all at once" has been directly responsible for making Java on the desktop unusable. I will be the first to say that Java has probably gotten a lot better since I got my JDK certification, but I have no reason to believe that "freeing all at once" is somehow better than doing incremental heap inserts. Particularly since the GC has to go hunting for the things it will be "freeing all at once".
Clear, Dark Skies
there is no difference.
Clear, Dark Skies
Those "interesting features" are nothing new, and you can get them on Linux, they're just not turned on by default (because they have overhead).
Retain/release and all that are implemented by the Objective C libraries, not libc.
about retain/release not being in libc; I seem to be confusing retain/release with allocator zones today.
Clear, Dark Skies
I'd like to know why isn't ObjC more popular outside Apple (and NeXT) circles?
For a long time, there was no usable free compiler available. And the reason for that is that NeXT only fulfilled the letter, but not the spirit of the GPL: they built their Objective C compiler on top of gcc, but they only gave back their modification under threat of a lawsuit, and then in a form that wasn't very usable.
If NeXT had given a usable Objective C frontend to GNU (as they should have under the GPL), and donated a usable Objective C standard library, there's a good chance that Objective C would be wildly popular on UNIX and Linux, because it was just the kind of language people needed in the 80's and 90's. Instead, C++, Java, and C# have taken over that void.
Lack of a use community has also kept Objective C from evolving; garbage collection should have and could have been added a decade ago, and there are some type safety issues in Objective C that also could have gotten fixed.
That's for Java, not a C-type language. Since Java does not permit access to memory pointers, GC can be made much more efficient; in a language derived from C, GC is never going to work well - there are too many ways to access memory directly.
Clear, Dark Skies
Actually, from first hand experience I can tell you that Linux can make a mockery of even the mallopt features that glibc says it supports.
Besides, why are you lecturing me about this? Someone asked a question, I said "no" and now you're lecturing me about what I have to do to change the answer to "yes"? Thanks, but I already know that.
Clear, Dark Skies
There seems to be a lot of cross communication in this thread.
Clear, Dark Skies
>I think that programmers should try to strive for the most effective coding strategy possible
too often, there are competing aims:
Vendor: maximize profit - cheap (short development time)
Customer #1: (the person whose budget is paying for the software) - minimize expense -
[you want the system to allow your users to accomplish their business objectives, and
maybe even to be 'happy' with the system]
Customer #2: (the person using the system every day) - minimize time 'wasted' using system
[here you want the objects in the system to make sense to your business]
Customer #3: (IT department providing tier 1 support for the system) - figure out how the system really works
[here you want the code to be easy to reason about and built mental models of how it really works]
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.
With a generational garbage collector there is a pool of memory in the young generation (typically called "eden") that new objects are allocated from, and they are all contiguous, and there is a pointer to the end of the allocated space. Allocating a block of memory is literally as cheap as incrementing that pointer.
On a somewhat related note, Joel wrote about the importance of languages which manage memory for you automatically in his article How Microsoft Lost the API War. It's from a while back but it's still a great read, so if you missed it, correct that right now.
Good mfences make good neighbors.
ROTFL.
You know, as someone who spends a lot of time dealing with the interactions between malloc and the OS, I find it extremely amusing that you think a sanity checker for the heap is a bad idea.
So, GC is good, but defending the heap is a bad idea?
Personally, I wish Linux had it. As it is, the unsafe implementation of malloc hooks in Linux leaves me forced to deal with races and timing holes, or with the "bad" decision of completely replacing the standard malloc library with my own.
Clear, Dark Skies
-fred
Sign #11 of Slashdot overdose: You see the phrase 'moderate Republican' and you wonder if that would be a +1 or a -1.
...is that it's better than any of the other ostensible 'Manuals of Style' out there that I've run into.
It's a great set of rules for beginners, and the fact that you don't know that ('no good author in the history of the English language') makes me a little depressed and sad. They never intended it to be a manual of style for e. e. cummings, they intended it to be a manual of style for George from Accounting and Fred the 'OMG my writting si so 1337!!11!1elevendy-one!' college student.
To learn to become an adequate writer, you need to learn the rules of writing. (Doesn't matter which rules, really, they just have to be self-consistent and lead to readable, concise writing that does not significantly offend the reader's sensibilities.) To learn to become a good writer, you need to learn when to break said rules. To learn to become a great writer, something I certainly haven't managed yet, you need to write. And write, and write, and write, and read, and write.
-fred
Sign #11 of Slashdot overdose: You see the phrase 'moderate Republican' and you wonder if that would be a +1 or a -1.
Oh, but I'm not a java head. I'm a Lisp hacker. And we've been "telling you so" since 1958...
:-)
Now all you need are macros (the ability to manipulate code as data so you can write code for the compiler, say) and you kids'll be all set. Of course, you'll need a more regular syntax and semantics for that... I know, how about something mathmatically based, like the lambda calculus?
-- I speak only for myself
From what's known so far, Objective C 2.0 also has some other interesting new features. It now has a "foreach"-style construct (actually for (x in blah)), and obj.property notation supporting internal getters and setters. God willing, maybe we'll soon see array/dictionary construction and access without ridiculous syntax like [[NSArray alloc] initWithObjects: ..., nil] and [array objectAtIndex:blah]. (Maybe the former could be shortened as @{a, b, c, ...}, like how NSString construction consists of C-style syntax prefixed with @. The latter has an obvious choice -- the array[blah] notation used everywhere else in the universe.)
"I finally look like a real person!" -- Lisa Simpson
"I finally look like a real programming language!" -- Objective-C
(Not that it wasn't a real programming language before; it just got ridiculous sometimes how much really basic syntactic sugar it lacked.)
Signature.
i am sorry if you can't remember to free your own damn memory then.. why are you writing code???
In a perfect world, every project gets all the time required to be completed with optimal efficiency and performance. In the real world, the idea is to limit scope, cost, and timeline so that you can accomplish the task as best as you can within the allotted time.
If you don't have to worry about freeing your memory, that's one less thing slowing your productivity. It's also one less possible source of bugs. In any team project, it is also one less source of problems from other developers. Now in certain applications where performance is paramount and a fine level of control is desired, manual memory management is the way to go.
In other applications, the developer time you save by using Objective C, Java, Perl, Python, Ruby, or whatever easily pays for any additional server hardware you require to run the less efficient code.
I know what you are saying and trust me i am not perfect at it and i have the same issues. but to me C/C++ seemed like the last place that needed this..
if you want something that does garbage collection use java.. if you want something to be lean and mean use C... It just seems like you are giving people tools to let them be less responsiable at their jobs.
a good question to look at with this is when something falls out of scope can get recycled by the collector to another thread does it bother to zero out the space before it hands it over if not i see major issues where something can now read info from another proccess that it shouldn't have access to. by adding this layer you are adding another set of problems...
I am not saying that garbage collection is a bad thing.. it fits an area in this world - but to be honest if you arn't worried about doing memory management you don't care if it is lean why not use something that already has it and is slower.. this Addition seems like making something that wasn't designed to do something fit a roll it isn't suited for an pointless.s
'...if only "Jumping to a Conclusion" was an event in the Olympics.'
dmalloc and other malloc debuggers work by using the existing glibc malloc-hook functionality. And, guess what? That functionality isn't thread safe.
This isn't about enabling debug features in the default malloc library, it's about not using a design methodology that's been well understood for the past 30 years. The debug hooks for glibc are broken. Period.
Clear, Dark Skies
valgrind uses dynamic instrumentation, electric-fence and dmalloc use link time symbol replacement (I suspect ccmalloc does, too).
dmalloc and valgrind are thread safe, and ccmalloc and electric-fence have thread-safe patches available.
As for the glibc hooks, they aren't intended for heavy duty debugging.
Your assertion that the glibc hooks aren't "thread safe" is meaningless; apparently, you don't even understand how they work or what thread safety means.
The situation in terms of malloc debugging is far better on Linux than on OS X. Lack of valgrind on OS X is a grave disadvantage.
But don't let reality stand in the way of your zealotry; when Apple catches up eventually, you'll then just be telling us how it was really Apple that invented it all, or at least perfected it, or whatever.
But to be honest if you aren't worried about writing in assembler you don't care if it is lean. It just seems like anything else is just giving people tools to be irresponsible in their jobs.
Yawn.
Seriously, are people still trotting out these arguments? Why do you think we have higher-level languages? It's not to be a test of a programmer's mettle.
...when an olditie like another C descendant imperative language receives hurrahs for finally getting GC, when much more modern, robust, type-and-thread-safe languages like Haskell, Scala, OCaml, Erlang and others go on pratically unoticed...
I don't feel like it...
When you overrelease, you are attempting to release data that had already been deallocated when its reference count hit zero. That could segfault, or start causing strange memory errors.
First, if the item still hasn't been collected by the autorelease mechanism, decrementing the counter won't hurt it. If it has truly already been freed, Apple's implementation of malloc has defenses that detect this and prevent a double-free from occurring.
Apple's malloc library is interesting. I assume that these kinds of defenses make it slower than it could be, but you actually have to enable a special debug mode if you want double-frees to cause program crashes.
Clear, Dark Skies