Coder Social home page Coder Social logo

Orphaned DOM Nodes about blazorgooglemaps HOT 19 CLOSED

rungwiroon avatar rungwiroon commented on August 14, 2024 2
Orphaned DOM Nodes

from blazorgooglemaps.

Comments (19)

valentasm1 avatar valentasm1 commented on August 14, 2024

Honsly i had this thought. Will check closer today

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

Objects are released from memory cache, but like you said not from JavaScript.
How you come with this conclusions? I mean i would like to monitor and to reproduce by myself.

from blazorgooglemaps.

FlySpray316 avatar FlySpray316 commented on August 14, 2024

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

It is not that it is impossible for me, i just dont want to waste time where someone already had done everything and know where to click and see bug.
I will wait for screenshots. Screenshots are always great :).

from blazorgooglemaps.

FlySpray316 avatar FlySpray316 commented on August 14, 2024

The attached screen shots are a series of actions...

home page 1.png
Fresh DOM starting at home page. Node count about 800

map page 2.png
Navigate to the map page whihc has heavy usage of your google map component. Node count about 3200

home page 3 before garbage collector.png as the file suggests, this is navigating away from map page back to the home page where we would expect a node count of about 800 again. but remains on about 3200.

home page 4 after gabage collector.png. clicking the garbage collector button in Chrome Dev Tools to trigger garbage collection, would expect the node count to return to 800. but instead remains high.

home page 4 after garbage collector - with JS Hack - I'e included one extra screen shot, following the same steps as aboive, but with my JS hack to delte the object array on Dispose() of Map Page. can see the node count returns to 850 (a little higher than before, but I can live).

home page 1

map page 2

home page 3 before garbage collector

home page 4 after garbage collector

home page 4 after garbage collector - with JS Hack

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

Big thumb up for description. Also bug is very good catch. I would give you medal if i could :). Great work.
Back to topic. It is a bit complicated to remove. Just to clear all array it is a bit risky and could break a lot of people apps. So here is my suggestion. Map dispose is always called as expected. So when it is called then iterate through all array items and check if item have property map and map guid is same as disposed map. If true then remove. Problem that it finds only elements. Events isnt catched since they are promises.
I found some way but need more testing.
In a while you could inherit map component and on dispose call js function similar like this with map guid.

disposeMapElements(mapGuid) {
        var keysToRemove = [];
       
        for (var key in _blazorGoogleMapsObjects) {
            if (_blazorGoogleMapsObjects.hasOwnProperty(key)) {
                var element = _blazorGoogleMapsObjects[key];
                if (element.hasOwnProperty("map")
                    && element.hasOwnProperty("guidString")
                    && element.map.guidString === mapGuid) {
                    keysToRemove.push(element.guidString);
                }
            }
        }

        for (var keyToRemove in keysToRemove) {
            if (keysToRemove.hasOwnProperty(keyToRemove)) {
                var elementToRemove = keysToRemove[keyToRemove];
                delete window._blazorGoogleMapsObjects[elementToRemove];
            }
        }
    },

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

I will try to test and release in week period.

from blazorgooglemaps.

FlySpray316 avatar FlySpray316 commented on August 14, 2024

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

You said code bellow solves your problem. So does it solve on app or while testing and clicking garbage collector button?

dispose: function () {
    delete window._blazorGoogleMapsObjects;
},

from blazorgooglemaps.

FlySpray316 avatar FlySpray316 commented on August 14, 2024

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

Hope will not ruin anything big :).
So removed part where promises(events) was added to array and part where elements is removed by they dependency of map. Code bellow.
Like you said you have to waith for garbage collector to fire. I have sense that there is better way to remove them faster.
Please check if all you functionality works as expected with package 0.6.6. Finger crossed.
https://www.nuget.org/packages/BlazorGoogleMaps/0.6.6

disposeMapElements(mapGuid) {
	var keysToRemove = [];
   
	for (var key in _blazorGoogleMapsObjects) {
		if (_blazorGoogleMapsObjects.hasOwnProperty(key)) {
			var element = _blazorGoogleMapsObjects[key];
			if (element.hasOwnProperty("map")
				&& element.hasOwnProperty("guidString")
				&& element.map.guidString === mapGuid) {
				keysToRemove.push(element.guidString);
			}
		}
	}

	for (var keyToRemove in keysToRemove) {
		if (keysToRemove.hasOwnProperty(keyToRemove)) {
			var elementToRemove = keysToRemove[keyToRemove];
			delete window._blazorGoogleMapsObjects[elementToRemove];
		}
	}
},

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

Have you tried @FlySpray316
Could you confirm that all good and i could close?

from blazorgooglemaps.

FlySpray316 avatar FlySpray316 commented on August 14, 2024

from blazorgooglemaps.

FlySpray316 avatar FlySpray316 commented on August 14, 2024

I've tested the 0.6.6 release... unfortunately the DOM Node count still seems to be increasing. :-(

Just to confirm, on dispose of the page, I'm calling Map.Dispose(); am I meant to be calling anything/something else to dispose?? if yes, let me know; I can re-run the test.

screenshots attached...

Home page with Fresh DOM Node Count...
1 Home Page Fresh DOM Node Count

Map Page with high DOM Node Count...
2 Map Page High DOM Node Count

Home page with Hich DOM Node count BEFORE calling Garbage Collector...
3 Home Page High DOM Node Count Before GC

Home page with High DOM Node count AFTER calling Garbage Collector...
4 Home Page High DOM Node Count After GC

While the node count does drop, it seems there are still references that are not getting released. If i was better with JS i would dive in and have a look, but I'd probably make it worse!! haha :)

This screenshot is me navigating to the map page and back to the home page several times, calling the Garbage Collector after each time.
5 Navigating to and from map page calling GC each time

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

Could you check number of element before and after with Object.keys(_blazorGoogleMapsObjects).length
Also after check what kind elements left in array _blazorGoogleMapsObjects . I assume removing it form array dont make dom node dissapear from stack. Aslo could you try to redirect from other page with refresh. As much as i read this is most reliable way to clear dom nodes.
Let my know your test results

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

@FlySpray316 did you make a new finding? Have you tried my suggestions?

from blazorgooglemaps.

FlySpray316 avatar FlySpray316 commented on August 14, 2024

Sorry i have not tired your suggestion yet, I've got to finish some other tasks first.
But in 3 weeks I can dedicate a full week to solving this. Will send you a note when I start work on it.

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

No rush. You are only one (i assume) which have such issue.

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

I will close this issue in couple weeks if i wont get any response.

from blazorgooglemaps.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.