Sponsored Links
My Products

Archive for the ‘Programming & Design’ Category

writing objectives

When writing Mac/Cocoa applications, do you absolutely *have* to use Objective-C? Would C++ suffice? What are the upsides of learning Objective-C as opposed to sticking with C++?

Read the rest of this entry »

management by objective

I’m doing some programming for the iPhone in Objective-C. I’ve used C and C++ for years (though not recently), so I’m familiar with calloc/malloc/free.

I’m not clear on how garbage collection works in Cocoa/ObjC, though. There’s something about it being automatic, something about it not being automatic, something about it being automatic but you have to switch it on… What’s the deal?

1) Please explain the relationship between alloc, dealloc, and release.

2) I’m sure my app has memory leaks all over the place - I’ve been worrying about getting it good enough to show off without taking care of the details. Any good tips for reviewing and making sure things go away when they need to?

Specific example:

Let’s say I use code like this in a controller:
SomeClass *foo = [[SomeClass alloc] someInit:bar];
[[self navigationController] pushViewController:foo animated:YES]

I’ve now allocated an object. Do I dealloc it when I’m done using it? Or is that done automatically by the controller? Do I want to do:

[foo release]

Right after the push, as I’ve seen in some sample code? Why?

What if you’re making an object that is only referenced in the scope of a block? E.g.

{
SomeClass *cat = [SomeClass alloc];
// do some stuff
}

Does the object expire when the block ends, or do I need to dealloc it there? What if I assign that value to a pointer that exists outside the block?

I’m just trying to make sense of it… I can see where release would reduce the use count for garbage collection, but then what’s the point of dealloc? Is the use of both release and dealloc mutually exclusive, or does dealloc just say “don’t bother with garbage collection, just get rid of this now”?

Are there differences with memory management for iPhone versus ordinary OSX Cocoa? I only need to know iPhone for now, but it would be nice to know in general.

I need a concise answer for an advanced user. I can RTFM, I’m just looking for a summary. A good suggestion of precisely which M to RTF would be nice :)
Thanks!

management by objective

I’m new to memory management as I originally learned java. I have an instance method which creates a new object using alloc and then returns it. My question is how do I release the object I create as after I return the object it loses scope and therefore there is no way to say [object release].
Can I just release the returned object after I have used it?

Thanks very much
Well that gives me some food for thought.
I know that when I create an object I am simply creating a pointer to a memory location which can store that type of object. Does that therefore mean that when I return the object I am in fact returning a pointer, or do I have to explicitly state that the method returns a pointer object? E.g.
{
ExampleObject *theObject = [[ExampleObject alloc] init];
return theObject;
/*Am I returning a pointer here or does the theObject now go out of scope, if not then according to the previous posts the calling method could simplyrelease the pointer once it has used it.*/
}

Read the rest of this entry »

writing objectives

I need to write aims and objectives in my project could please anyone help me. Thanks