nnhubbard / ZSSRichTextEditor

A beautiful rich text WYSIWYG editor for iOS with a syntax highlighted source view
MIT License
3.78k stars 584 forks source link

UIViewController not dealloc #146

Open xiabob opened 7 years ago

xiabob commented 7 years ago

ZSSRichTextEditor.m line1706 /*

 Callback for when text is changed, solution posted by richardortiz84 https://github.com/nnhubbard/ZSSRichTextEditor/issues/5

 */
JSContext *ctx = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
ctx[@"contentUpdateCallback"] = ^(JSValue *msg) {

    if (_receiveEditorDidChangeEvents) {

        [self editorDidChangeWithText:[self getText] andHTML:[self getHTML]];

    }

    [self checkForMentionOrHashtagInText:[self getText]];

};
[ctx evaluateScript:@"document.getElementById('zss_editor_content').addEventListener('input', contentUpdateCallback, false);"];

maybe you should use weak self here

ghost commented 7 years ago

@xiabob where do you think weak self should be used? Do you want to submit a pull request for this?

xiabob commented 7 years ago
__weak __typeof(self)weakSelf = self;
ctx[@"contentUpdateCallback"] = ^(JSValue *msg) {

    if (weakSelf.receiveEditorDidChangeEvents) {

        [weakSelf editorDidChangeWithText:[weakSelf getText] andHTML:[weakSelf getHTML]];

    }

    [weakSelf checkForMentionOrHashtagInText:[weakSelf getText]];

};

try this,it works for me.is three a retain cycle here?

ghost commented 7 years ago

@xiabob I will try your solution.

ghost commented 7 years ago

@xiabob I have just tried your solution and it is not working.

xiabob commented 7 years ago

@william205 Thank you for your reply, my question is this: image image image but check with instruments, no leak happened

image image why these happened?

Jacky-LinPeng commented 4 years ago

[contentController addScriptMessageHandler:self name:@"jsm"]; cause leak