views:

49

answers:

2

Hi everyone, I was wondering if I should use an nsdictionary to hold all of the values that my program uses. Or, I could stick with using many variables for each value.

If I use an NSDictionary/array I could release it all at once, rather than a bunch of variables. Unfortunately I am dealing with many memory leaks, so I thought that using an NSdictionary/array could help with the memory leaks.

A: 

Misusing is always bad; only use NSDictionary/arrays when you need container. Better read docs and avoid memory leaks as the rest of us avoid them: write proper code.

Vadim Shender
I'm a newbie to objective-c, what is a container?
alexy13
alexy13: It's not an Objective-C-specific concept. A container is an object that contains other objects. Arrays, sets, and dictionaries are the most common kinds of containers in Cocoa.
Peter Hosey
Thanks, I understand it now
alexy13
+2  A: 

I guess it depends a bit on your application, but I would highly recommend that you look into Object Oriented Programming instead of using arrays, variables, etc.

I mean, technically, you'd still have those, but you would have an array of objects that would contain the variables you need, and it would know how to save itself if you implement the correct methods.

Topher Fangio
Sounds interesting, I'll look into this right now.
alexy13
Thank you for the answer, it really makes my code look nice and neat :D
alexy13