воскресенье, 6 марта 2011 г.

MemCheck description in english

MemCheck helps to find memory leaks in your iOS applications. It can register alloc, retain and release calls for NS-objects and show detail information in console.

Sources

https://github.com/soniccat/memCheck-for-iOS

Connect the library

Add 6 files to your project:

NSMemCheckObject.h
NSMemCheckObject.m
NSMutableArray+MemCheck.h
NSMutableArray+MemCheck.m
NSObject+MemCheck.h
NSObject+MemCheck.m
add in the tail of your pch file

#define MEMTEST_ON

add in the top of the application: didFinishLaunchingWithOptions: function

#ifdef MEMTEST_ON
[NSObject turnMemCheckOn];
#endif

Using

When you app is running in any moment you can press the pause button and print in the Xcode's console:

po [memData allMem]

14 items

(
"2011-02-23 06:47:04 +0000 memCheckObject 0x4b45840 object 0x4b45530 stack 0x4b45a00 NSCountedSet",
"2011-02-23 06:47:04 +0000 memCheckObject 0x4e16040 object 0x4e15d00 stack 0x4e15c40 NSAutoreleasePool",
"2011-02-23 06:47:04 +0000 memCheckObject 0x4e10cc0 object 0x4b0de50 stack 0x4e14ef0 __NSPlaceholderDictionary",
"2011-02-23 06:47:04 +0000 memCheckObject 0x4b44ab0 object 0x4b44a90 stack 0x4b42d10 CALayerArray",
"2011-02-23 06:47:04 +0000 memCheckObject 0x4e16cd0 object 0x4e02b80 stack 0x4e16f40 __NSPlaceholderArray",
"2011-02-23 06:47:04 +0000 memCheckObject 0x4e151d0 object 0x4e14ec0 stack 0x4e16380 NSKeyValueMethodSetter",
"2011-02-23 06:47:04 +0000 memCheckObject 0x4e15040 object 0x4e15190 stack 0x4e16060 CALayer",
"2011-02-23 06:47:04 +0000 memCheckObject 0x4e0faf0 object 0x4e08960 stack 0x4e15d20 __NSPlaceholderSet",
"2011-02-23 06:47:04 +0000 memCheckObject 0x4e14de0 object 0x4b10790 stack 0x4e14f60 NSPlaceholderString",
"2011-02-23 06:47:04 +0000 memCheckObject 0x4e06c60 object 0x4b3fdc0 stack 0x4e106f0 NSAutoreleasePool",
"2011-02-23 06:47:04 +0000 memCheckObject 0x4b41cd0 object 0x4b41750 stack 0x4b43450 __NSPlaceholderDate",
"2011-02-23 06:47:04 +0000 memCheckObject 0x4b44100 object 0x4b440f0 stack 0x4b440a0 __NSPlaceholderTimeZone",
"2011-02-23 06:47:04 +0000 memCheckObject 0x4b43680 object 0x4e02b70 stack 0x4b438f0 __NSPlaceholderArray",
"2011-02-23 06:47:04 +0000 memCheckObject 0x4b41960 object 0x4b02420 stack 0x4b43750 NSObject"

)

14 is all registered objects, which exist in memory at this moment. The list starts with last allocated object.
an address after memCheckObject point to wrapper object
an address after object point to allocated object
an address after stack point to alloc callstack
in end of line allocated an object's class name is displayed

po [memData top:N]

return only N last allocated objects

po address_of_object

display a defaul object's description

po address_of_callstack

display a stack like that

<_nscallstackarray>(
0 CoreFoundation 0x00da9be9 __exceptionPreprocess + 185,
1 libobjc.A.dylib 0x00efe5c2 objc_exception_throw + 47,
2 inFoundation 0x00002796 +[NSObject(memCheck) myAllocFunc] + 918,
3 inFoundation 0x00001c81 -[inFoundationAppDelegate application:didFinishLaunchingWithOptions:] + 161,
4 UIKit 0x002b31fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163,
...
)

po [address_of_wrapper_object history]

display a callstacks for alloc, retain and release functions, ordered by date. It shows like that:

ALLOC:

2011-02-23 06:26:56 +0000

(

0 CoreFoundation 0x00dacbe9 __exceptionPreprocess + 185

1 libobjc.A.dylib 0x00f015c2 objc_exception_throw + 47

2 memCheck 0x0000310f +[NSObject(memCheck) myAllocFunc] + 831

3 memCheck 0x000024d2 -[inFoundationAppDelegate application:didFinishLaunchingWithOptions:] + 98

4 UIKit 0x002b61fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163

...

)

RETAIN:

2011-02-23 06:26:56 +0000

(

0 CoreFoundation 0x00dacbe9 __exceptionPreprocess + 185

1 libobjc.A.dylib 0x00f015c2 objc_exception_throw + 47

2 memCheck 0x000034cf -[NSObject(memCheck) myRetainFunc] + 335

3 CoreFoundation 0x00cbf0bc CFRetain + 92

4 CoreFoundation 0x00da5db5 +[__NSArrayI __new::] + 117

5 CoreFoundation 0x00d188a3 +[NSArray arrayWithObject:] + 67

6 memCheck 0x00002508 -[inFoundationAppDelegate application:didFinishLaunchingWithOptions:] + 152

7 UIKit 0x002b61fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163

...

)

RETAIN:

2011-02-23 06:26:56 +0000

(

0 CoreFoundation 0x00dacbe9 __exceptionPreprocess + 185

1 libobjc.A.dylib 0x00f015c2 objc_exception_throw + 47

2 memCheck 0x000034cf -[NSObject(memCheck) myRetainFunc] + 335

3 memCheck 0x00002538 -[inFoundationAppDelegate application:didFinishLaunchingWithOptions:] + 200

4 UIKit 0x002b61fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163

...

)

RELEASE:

2011-02-23 06:26:56 +0000

(

0 CoreFoundation 0x00dacbe9 __exceptionPreprocess + 185

1 libobjc.A.dylib 0x00f015c2 objc_exception_throw + 47

2 memCheck 0x000037ee -[NSObject(memCheck) myReleaseFunc] + 302

3 memCheck 0x0000258d -[inFoundationAppDelegate application:didFinishLaunchingWithOptions:] + 285

4 UIKit 0x002b61fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163

...

)

RETAIN:

2011-02-23 06:26:56 +0000

(

0 CoreFoundation 0x00dacbe9 __exceptionPreprocess + 185

1 libobjc.A.dylib 0x00f015c2 objc_exception_throw + 47

2 memCheck 0x000034cf -[NSObject(memCheck) myRetainFunc] + 335

3 CoreFoundation 0x00cbf0bc CFRetain + 92

4 CoreFoundation 0x00da5db5 +[__NSArrayI __new::] + 117

5 CoreFoundation 0x00d188a3 +[NSArray arrayWithObject:] + 67

6 memCheck 0x000025ae -[inFoundationAppDelegate application:didFinishLaunchingWithOptions:] + 318

7 UIKit 0x002b61fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163

...

)

po [address_of_wrapper_object retains] and po [address_of_wrapper_object releases]

return callstacks for all retain or release calls, started with last.

po [memData markHeap]

save a current date which divide the allocated object list on earlier and later groups

po [memData showHeaps]

show allocated groups divided by saved dates

po [memData objectsForHeap:n]

return an allocated object list in selected group

Комментариев нет:

Отправить комментарий