Re: If No Memory Leaks, Is It Good Enough for Memory Management?
Re: If No Memory Leaks, Is It Good Enough for Memory Management?
- Subject: Re: If No Memory Leaks, Is It Good Enough for Memory Management?
- From: Scott Ellsworth <email@hidden>
- Date: Mon, 20 Jun 2011 10:23:20 -0700
On Mon, Jun 20, 2011 at 12:26 AM, Bing Li <email@hidden> wrote:
> Dear all,
>
> I am still a new programmer of Cocoa. In my program, at least right now,
> there are no memory leaks according to Instruments. Is it good enough for
> memory management?
No. This is not good enough.
If you are doing your memory management at the objc level, you should
read the memory management guide very carefully. Especially look into
autorelease, as the "memory goes up a bunch, then drops when the next
event loop spins" sounds much like the standard autorelease behavior.
If you are doing it at the C (malloc/free) or CF (some fn call that
says CF...Alloc or CF...Retain and corresponeding CF...Free/Release)
levels, read the APIs that go along with those, and figure out when
your memory is being allocated and when it is being freed or released
back to the system.
>
> What I designed is a TCP server which receives TCP messages. When I tested
> it, 200,000 XML were sent to it with a loop without any delays. Each XML had
> 800 bytes. In this case, no any memory leaks when testing it with
> Instruments. However, according to Activity Monitor, the consumed memory was
> increased from 17.9M to more than 400M. Immediately after the sending, the
> consumed memory started to be lowered until it was stopped to 100M. Was it
> normal? Why wasn't it 17.9M eventually?
Sounds like your program still owns some memory, and is holding on to
too much memory during execution. Neither ActivityMonitor nor
Instruments is a true memory profiler, but they are good ways to
figure out some areas where you might have a problem.
The true lesson - learn ObjC or C memory management, and do it right
every time, or leak RAM and have angry users. You are doing the right
thing by asking here for pointers.
Scott
>
> Thanks so much for your help!
>
> Best,
> greatfree
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden