I'm working on a small app that provides information similar to coconut battery, but plugs into the menu bar. Not exactly groundbreaking, it's more a hobby for me right now
The app relies on IOKit to access the battery information.
After launching the app, it uses about 10 MB of memory. However I noticed that after about a week of running, the memory usage is up to about 100 MB, and keeps growing at a very slow rate. Steps taken:
Enabled ARC (automatic reference counting) and adjusted the code accordingly. No change.
Used Instruments and found that IOkit leaked a few kb per minute - the app checks the battery status every 10 seconds, and each time it would leak some memory.
Disabled ARC, enabled garbage collection. This apparently closed most leaks, the app is down to leaking 20 KB per hour. At this point a small leakage occurs every few minutes, and doesn't seem to be correlated with any particular action inside the program.
At this point I should probably stop worrying... a full month of running would make the app use 20 MB. For comparison, I ran coconut battery through instruments, and it turns out to leak about the same amount of memory.
Below is a screenshot of instruments - it seems to indicate that the leak is somewhere deep within IOKit. However I'm well aware in most cases it's still a user error.
Also below is the relevant snipplet of the method that is called every 10 seconds:
I should probably try to manually release stuff (when implementing ARC, you have to remove all retain/release cycles).
The app relies on IOKit to access the battery information.
After launching the app, it uses about 10 MB of memory. However I noticed that after about a week of running, the memory usage is up to about 100 MB, and keeps growing at a very slow rate. Steps taken:
Enabled ARC (automatic reference counting) and adjusted the code accordingly. No change.
Used Instruments and found that IOkit leaked a few kb per minute - the app checks the battery status every 10 seconds, and each time it would leak some memory.
Disabled ARC, enabled garbage collection. This apparently closed most leaks, the app is down to leaking 20 KB per hour. At this point a small leakage occurs every few minutes, and doesn't seem to be correlated with any particular action inside the program.
At this point I should probably stop worrying... a full month of running would make the app use 20 MB. For comparison, I ran coconut battery through instruments, and it turns out to leak about the same amount of memory.
Below is a screenshot of instruments - it seems to indicate that the leak is somewhere deep within IOKit. However I'm well aware in most cases it's still a user error.
Also below is the relevant snipplet of the method that is called every 10 seconds:
Code:
- (void) updateBatteryInfo
{
// go to battery entry!
ioRegistryRoot =
IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/AppleACPIPlatformExpert/SMB0/AppleECSMBusController/AppleSmartBatteryManager/AppleSmartBattery");
// read out properties
tester=IORegistryEntryCreateCFProperties(ioRegistryRoot, &properties, kCFAllocatorDefault,0);
// set above values!
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, CFSTR("CycleCount")), 9, &CycleCount);
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, CFSTR("CurrentCapacity")), 9, &CurrentCharge);
// more of the same commands
}
I should probably try to manually release stuff (when implementing ARC, you have to remove all retain/release cycles).