Memory Leak, No Way!

Today I encountered the following debugger output when I ran my iPad application code:

2011-07-18 23:09:50.205 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b0fc60 of class __NSArrayM autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.207 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b10960 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.209 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b11bd0 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.211 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b11f60 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.211 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b12170 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.212 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b12380 of class __NSArrayI autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.212 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b124d0 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.213 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b125e0 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.214 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b12cf0 of class UIDeviceRGBColor autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.214 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b13010 of class __NSArrayM autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.215 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b0f960 of class __NSArrayM autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.216 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b12f80 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.216 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b13130 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.217 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b13030 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.217 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b132d0 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.218 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b131b0 of class __NSArrayI autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.219 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b131c0 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.219 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b134f0 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.220 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b133d0 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.221 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b13680 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-07-18 23:09:50.222 Whiteboard[55591:207] *** __NSAutoreleaseNoPool(): Object 0x4b13640 of class NSConcreteData autoreleased with no pool in place - just leaking

This is quite confusing, because for each background thread, I created its own NSAutoreleasePool, and of cource the main thread's NSAutoreleasePool is just out there in main.m, so what's the problem ? I use Instruments's leak detecting tool, it shows when the application bootstrap, it calls my singleton class ActionManager's load method which I used to load the data as a class helper method ([ActionManager load]). I suddenly realize that the problem is here !

Since each NSObject defines a load method as the cocoa documentation says: "Invoked whenever a class or category is added to the Objective-C runtime; implement this method to perform class-specific behavior upon loading". When the app runs, it call every needed class' load method. The ActionManager's load method is mistakenly override by me, that's why the debugger output these messages (Hmm, it even crashes my iPad sometimes). 

Install informix on Mac OS X

For variable reasons, I installed the informix server on my Mac OS X(10.6.7) several times. But each time after installing it, I needed to figure out some wired things that prevent it running correctly, it's really annoying and time consuming. So I wrote this article to describe the key step to make the server working as expected.

  1. Download the informix develop edition 11.70 from http://www.ibm.com/developerworks/downloads/im/informix/ the download file is iif.11.70.FC1DE.macosx64.dmg for mac os x.
  2. Click ids_install.app to launch the GUI tool, folowing http://apps.topcoder.com/wiki/display/docs/TopCoder+Databases+Setup+Guide to install a 'informixoltp_tcp' database on port 'xxxxx'
  3. Open terminal, login as user informix using command su - informix, add the following lines (assuming the informix is intalled to /Tools/informix) to ~/.bash_profile:
    INFORMIXDIR=/Tools/informix
    INFORMIXSERVER=informixoltp_tcp
    ONCONFIG=onconfig.informixoltp_tcp
    INFORMIXSQLHOSTS=/Tools/informix/etc/sqlhosts.informixoltp_tcp
    
    PATH=${INFORMIXDIR}/bin:${INFORMIXDIR}/extend/krakatoa/jre/bin:${PATH}
    
    export INFORMIXDIR INFORMIXSERVER ONCONFIG INFORMIXSQLHOSTS PATH
    
  4. Excute . ~/.bash_profile to reload the bash profile, excute oninit -iv to initialize the informix database. You may probably get the shared memory not initialized error, to resovle the error, change FULL_DISK_INIT to 0 in $INFORMIXDIR/etc/onconfig.informixoltp_tcp, and then excute oninit -iv again, it will succeed.
  5. To verify the server state, excute onstat -, if IBM Informix Dynamic Server Version 11.70.FC1DE -- On-Line -- Up 00:45:53 -- 281744 Kbytes shows, then it successfully starts. (To shutdown the server, use onmode -ky, for normal starting,  use oninit -v
  6. You can now use dbaccess to connect to the informix database, but when you use jdbc to connect, you will find the server refuses the connection, I am not sure whether or not it's a bug of the informix, you need to take the following step to make it working:
    informixoltp_tcp onsoctcp 127.0.0.1 yourport 
    
  7. Restart the server, everything works well now !