在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:facebook/FBRetainCycleDetector开源软件地址:https://github.com/facebook/FBRetainCycleDetector开源编程语言:Objective-C++ 51.0%开源软件介绍:FBRetainCycleDetectorAn iOS library that finds retain cycles using runtime analysis. AboutRetain cycles are one of the most common ways of creating memory leaks. It's incredibly easy to create a retain cycle, and tends to be hard to spot it. The goal of FBRetainCycleDetector is to help find retain cycles at runtime. The features of this project were influenced by Circle. InstallationCarthageTo your Cartfile add:
CocoaPodsTo your podspec add:
You'll be able to use Example usageLet's quickly dive in #import <FBRetainCycleDetector/FBRetainCycleDetector.h> FBRetainCycleDetector *detector = [FBRetainCycleDetector new];
[detector addCandidate:myObject];
NSSet *retainCycles = [detector findRetainCycles];
NSLog(@"%@", retainCycles);
Example output could look like this:
FBRetainCycleDetector will look for cycles that are no longer than 10 objects. We can make it bigger (although it's going to be slower!). FBRetainCycleDetector *detector = [FBRetainCycleDetector new];
[detector addCandidate:myObject];
NSSet *retainCycles = [detector findRetainCyclesWithMaxCycleLength:100]; FiltersThere could also be retain cycles that we would like to omit. It's because not every retain cycle is a leak, and we might want to filter them out. To do so we need to specify filters: NSMutableArray *filters = @[
FBFilterBlockWithObjectIvarRelation([UIView class], @"_subviewCache"),
];
// Configuration object can describe filters as well as some options
FBObjectGraphConfiguration *configuration =
[[FBObjectGraphConfiguration alloc] initWithFilterBlocks:filters
shouldInspectTimers:YES];
FBRetainCycleDetector *detector = [[FBRetainCycleDetector alloc] initWithConfiguration:configuration];
[detector addCandidate:myObject];
NSSet *retainCycles = [detector findRetainCycles]; Every filter is a block that having two Check FBStandardGraphEdgeFilters to learn more about how to use filters. NSTimerNSTimer can be troublesome as it will retain it's target. Oftentimes it means a retain cycle. FBObjectGraphConfiguration *configuration =
[[FBObjectGraphConfiguration alloc] initWithFilterBlocks:someFilters
shouldInspectTimers:NO];
FBRetainCycleDetector *detector = [[FBRetainCycleDetector alloc] initWithConfiguration:configuration]; AssociationsObjective-C let's us set associated objects for every object using objc_setAssociatedObject. These associated objects can lead to retain cycles if we use retaining policies, like #import <FBRetainCycleDetector/FBAssociationManager.h>
int main(int argc, char * argv[]) {
@autoreleasepool {
[FBAssociationManager hook];
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
} In the code above Getting CandidatesIf you want to profile your app, you might want to have an abstraction over how to get candidates for
ContributingSee the CONTRIBUTING file for how to help out. License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论