$timezone = 'America/Los_Angeles'; date_default_timezone_set($timezone); ?>
If you want something done right, do it yourself!
Every time I start a project with a cool new toy that does magic, I find myself troubleshooting the basics more than coding and using this magic. This is not to say that the magic isn't cool, but it takes some getting used to.
Here is my memory leak journey while writing SeaWall.
The new toy in question: ARC. Well, okay... new to me.
Growing up, I learned the hard way what happens when you don't unallocate the used memory. Then in college, I learned a little bit "harder" when going though Operating System Pragmatics where we wrote our own OS.
thou shalt not allocate memory and forget to set it free
Somewhere along the way I forgot this. Well not really. I just heard ARC and assumed JGC and got myself into trouble. A lot of trouble.
1.5 GB in less than a minute. That's bad.
So why isn't ARC working?
Code:
int doStuff(NSDirectoryEnumerator *ptr){ while((filename = [direnum nextObject] )) { NSData *nsData = [NSData dataWithContentsOfFile:filename]; // do some other stuff all declaring the variable within the scope of the while } }
Nothing too bad here... right?
@autoreleasepool
to the rescue, or so I thought.
Code:
int doStuff(NSDirectoryEnumerator *ptr){ while((filename = [direnum nextObject] )) { @autoreleasepool{ NSData *nsData = [NSData dataWithContentsOfFile:filename]; // do some other stuff all declaring the variable within the scope of the while } } }
Turns out that the while loop
was unpacking itself on the heap dynamically and each iteration was not letting go of the last.
Code:
int doStuff(NSDirectoryEnumerator *ptr){ while(true) { @autoreleasepool{ if(!(filename = [direnum nextObject])){ break; ) NSData *nsData = [NSData dataWithContentsOfFile:filename]; // do some other stuff all declaring the variable within the scope of the while } } }
Now I know better. Alway be super careful with "magic." Well, not really magic. If it feels like magic, then you just don't understand it well enough. Take the time to learn it.