Above link is a similar question what Im about to ask. But I couldn't find any official reference about that answer.
public uploadImage() {
const input: HTMLInputElement = document.createElement('input');
input.type = 'file';
input.accept = 'image/png';
const onChange = () => {
const file = input.files[0];
const reader = new FileReader();
const onError = () => {
reader.abort();
alert('image loading failed');
};
const onLoadEnd = (evt) => {
if (evt.target.readyState === 2) {
this.readImageByBase64(evt.target.result as string);
} else {
onError();
}
};
reader.addEventListener('loadend', onLoadEnd);
reader.addEventListener('error', onError);
reader.readAsDataURL(file);
};
input.addEventListener('change', onChange);
input.click();
}
According to answer to above question, since the input
variable and reader
variable is function scoped, will event listener be removed from the element and will onLoadeEnd
and onError
be garbage collected? If yes, are there any background information or reference about it?(more focused about removing event listeners then garbage collection)