The tool address is as follows: github.com/wing3501/Bi…

The cause of

Recently, it was found that the peak memory occupancy in APP live broadcast room was very high. After checking, it is because in the chat list, part of the user profile picture is caused by the original picture. The APP memory usage is too high, causing OOM. Procedure When the APP is in the background, when the mobile phone memory is short, the system will first kill the APP that occupies a large memory. Blah, blah, blah, blah, blah. The image cache managed by SDWebimage is usually released on memory warnings, but images should be used as reasonably as possible. In general, we optimize the use of images in the following ways:

1. Use a size image address such as www.xxxx.xxx-W800H800/w/64 2. Using the SDWebimage zoom option SDWebImageScaleDownLargeImages 3. Picture zooming and so on…

preface

Despite caution, the business grows, and you never know when something might go wrong in your code. So, I wrote a small tool to detect the project using a large picture. Personal level is limited for reference only.

Results the following

  • If the image is a network image, collect information about the view where the image resides
  • If the image is local, collect the image name or path
  • If the image is created from NSdata, the stack information at the time the image was created is collected

Personal ideas

@interface UIView (SDBigImageTracker) - (void)my_sd_setImage:(UIImage *)image imageData:(NSData *)imageData basedOnClassOrViaCustomSetImageBlock:(id)setImageBlock transition:(id)transition cacheType:(NSInteger)cacheType imageURL:(NSURL *)imageURL; @end @interface UIImage (SDBigImageTracker) + (nullable UIImage *)my_imageNamed:(NSString *)name; + (nullable UIImage *)my_imageNamed:(NSString *)name inBundle:(nullable NSBundle *)bundle withConfiguration:(nullable UIImageConfiguration *) configuration API_AVAILABLE (ios (13.0)); + (nullable UIImage *)my_imageNamed:(NSString *)name inBundle:(nullable NSBundle *)bundle compatibleWithTraitCollection:(nullable UITraitCollection *)traitCollection; + (nullable UIImage *)my_imageWithContentsOfFile:(NSString *)path; + (nullable UIImage *)my_imageWithData:(NSData *)data; + (nullable UIImage *)my_imageWithData:(NSData *)data scale:(CGFloat)scale; @endCopy the code

In the project, SDWebimage is basically used to load network images. So I hooked SDWebimage to set the image after downloading the image and decoding it. Used to get the size and view of the decoded image.

For local images, the image name or local path is recorded when the UImage is created. Set a timer to check if the image decoding is complete.

For images created from NSData, get the create stack for easy location.