iOS 内存泄露BUG列举
2018-05-08 本文已影响25人
F森
1.检查是否可以使用内购
#import <StoreKit/StoreKit.h>
BOOL can = [SKPaymentQueue canMakePayments];
NSLog(@"%d",can);
使用Leak
内存泄露工具检查可以看到有内存泄露
2.获取本机DNS
+ (NSArray *)getDNSs {
res_state res = malloc(sizeof(struct __res_state));
int result = res_ninit(res);
NSMutableArray *servers = [[NSMutableArray alloc] init];
if (result == 0) {
union res_9_sockaddr_union *addr_union = malloc(res->nscount * sizeof(union res_9_sockaddr_union));
res_getservers(res, addr_union, res->nscount);
for (int i = 0; i < res->nscount; i++) {
if (addr_union[i].sin.sin_family == AF_INET) {
char ip[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &(addr_union[i].sin.sin_addr), ip, INET_ADDRSTRLEN);
NSString *dnsIP = [NSString stringWithUTF8String:ip];
[servers addObject:dnsIP];
} else if (addr_union[i].sin6.sin6_family == AF_INET6) {
char ip[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &(addr_union[i].sin6.sin6_addr), ip, INET6_ADDRSTRLEN);
NSString *dnsIP = [NSString stringWithUTF8String:ip];
[servers addObject:dnsIP];
}
}
free(addr_union);
}
res_nclose(res);
free(res);
return [NSArray arrayWithArray:servers];
}
产生内存泄露的代码是:int result = res_ninit(res);