Cocoanetics / DTCoreText

Methods to allow using HTML code with CoreText
BSD 2-Clause "Simplified" License
6.34k stars 1.18k forks source link

Seems DTTiledLayerWithoutFade will cause some memory crash when using with DTLazyImageView #1225

Open ximmyxiao opened 3 years ago

ximmyxiao commented 3 years ago

In my project , I will receive some crash logs (not happened very frequent) like this :

libobjc.A.dylib objc_retain
iKM __25+[UIImageView(QMUI) load]_block_invoke_3 (UIImageView+QMUI.m:)
iKM -[DTLazyImageView completeDownloadWithData:] (DTLazyImageView.m:)
Foundation ___NSThreadPerformPerform
libdyld.dylib _start

And after my digging in to it , I found I can reproduce this problem , it's just because the CALayer object of DTLazyImageView will be dealloc before the the DTLazyImageView deallocing , And I can reproduce this crash with the DTCoreText Demo after changeing the performSelectorOnMainThread to this (just add a dispatch after 2 seconds to simulate the real network conditions)

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
            [self performSelectorOnMainThread:@selector(completeDownloadWithData:) withObject:_receivedData waitUntilDone:YES];

            _receivedData = nil;
        });

And the image.html will just leave remote images only

Image Handling

<h2>Remote Images</h2>
<p>Images can also be loaded from remote URLs, even without specifying a size in the HTML. The code demonstrates how to update the DTTextAttachment's display size after download and triggering a re-layout.</p>
<img src="https://www.cocoanetics.com/files/Cocoanetics_Square.jpg">

And after these works be done , run the demo , click the 'Image Handling' to push the controller in , and pop it out soon , the program will crash soon.

And If I don't use the DTTiledLayerWithoutFade ,the program will works very well ,

And I can avoid this crash with a strong-weak dance of block , But I think the DTLazyImageView 'layer object becomes a zombie before the DTLazyImageView object dealloc it self is not normal,it means some problem behind it , and I 'm quite sure it has something to do with DTTiledLayerWithoutFade layer class , It seems that the SubView's layer will be dealloced by CATiledLayer unexpected. But I don't know how to fix the DTTiledLayerWithoutFade.

So If any more about crash is needed ,just let me know. thanks

ximmyxiao commented 3 years ago

A demo simulating this kind of CATiledLayer crash can be download from here: https://github.com/ximmyxiao/TestTiledLayerDealloc

ankitpoplify commented 2 years ago

I am also facing this issue. @ximmyxiao Did you find a solution for it?

ximmyxiao commented 2 years ago

@ankitpoplify ,sorry , still did not fix it, seems some over-release problem , but it seems hard to know where is the reason

ximmyxiao commented 2 years ago

@ankitpoplify see my lastest issue comments , maybe you can try it