Infowindow with a div inside

67 views
Skip to first unread message

Gianpiero Venditti

unread,
Sep 16, 2011, 3:55:57 AM9/16/11
to google-map...@googlegroups.com
Hello, I have a doubt about the infowindow behaviour.
Let's say that I construct an infowindow with a div inside and i connect it to a marker with a listener.

Then if i want to remove the infowindow what's the best way to do it in order to release memory occupied by the infowindow?

And also do i have to explicitly remove the div inside the infowindow from the DOM?

Thanks in advance for the help.

Pil

unread,
Sep 16, 2011, 4:47:10 AM9/16/11
to Google Maps JavaScript API v3
Not sure about the intention of your question.

Infowindows do constist of many many divs. Sould not matter very much
when you create a further div that contains your content.

I'd suggest to have a look at the DOM structure of infowindows using
Firebug. There you can also see the results when certain divs are
removed.

Why do you want to remove the infowindow after it's being used? The
Maps API is not designed to do that. I think you should let the API do
it's own job unless you detect that it does it's job extremly
inefficient.

Even in this case you should be aware: Manipulating the DOM
subsequently and from outside is probably inefficient anyway.

So it's generally no good idea to change the DOM created by the API.
If you detected a bug or a reproducable memory leak, why don't you
report that?




On Sep 16, 9:55 am, Gianpiero Venditti <gianpiero.vendi...@gmail.com>
wrote:

Gianpiero Venditti

unread,
Sep 16, 2011, 4:58:11 AM9/16/11
to google-map...@googlegroups.com
Thanks for the quick answer, maybe i explained myself bad.

What i would like to know is this:

1 - I create a visible marker with an infowindow that contains a div
2 - I remove this marker from the map using marker.setMap(null)

Do i have to take care of removing the infowindow element or the removal is automatic when its correspondent marker is removed?

Pil

unread,
Sep 16, 2011, 6:02:50 AM9/16/11
to Google Maps JavaScript API v3
Yes, I think the question is important because it's an issue of
efficiency.

Don't think that some related element or a corresponding event
listener is removed 'automatically' when the marker is removed from
the map. Can definitely make sense to remove them separately and every
time after they have been used and additionally to delete the marker
object - especially when otherwise many ot them are existing in the
'background' memory.






On Sep 16, 10:58 am, Gianpiero Venditti <gianpiero.vendi...@gmail.com>
wrote:

Gianpiero Venditti

unread,
Sep 16, 2011, 6:42:54 AM9/16/11
to google-map...@googlegroups.com
Ok thanks, but then what's the best way to delete an infowindow?

In the api reference i don't see anything in particular except for the close() method.

And also what's the best way to delete the internal div I created for the content?

Pil

unread,
Sep 16, 2011, 7:15:33 AM9/16/11
to Google Maps JavaScript API v3
Can you provide a link to your map?


On Sep 16, 12:42 pm, Gianpiero Venditti <gianpiero.vendi...@gmail.com>
wrote:

Gianpiero Venditti

unread,
Sep 16, 2011, 7:37:18 AM9/16/11
to google-map...@googlegroups.com
Actually I don't have a working example yet.

Since i'm planning an application with an embed google map which will need to move markers at regular intervals i was just giving a look at the api.

So it came to me the question about the destruction of the infowindow and the release of the memory.

I would like to know if there are some guidelines to delete an infowindow and free its memory when a marker is deleted from the map.

Florian Behr

unread,
Sep 16, 2011, 8:03:36 AM9/16/11
to google-map...@googlegroups.com
If you want to remove the DOM and the object you use the close() method (DOM) and then set your var to null (memory) to ensure that it's being properly garbage collected.

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-maps-js-api-v3/-/K5gyrrfNclIJ.

To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Pil

unread,
Sep 16, 2011, 8:37:08 AM9/16/11
to Google Maps JavaScript API v3


On Sep 16, 1:37 pm, Gianpiero Venditti <gianpiero.vendi...@gmail.com>
wrote:
would like to know if there are some guidelines to delete an
infowindow
> and free its memory when a marker is deleted from the map.


I don't know such a guideline. So in fact it seems that you detected
an unclosed gap.

For most of the developers I'd suspect the whole subject isn't very
important, because the main intention is to get a running map and
that's it.

In addition to what Florian already said I'd suggest storing the
listeners for removable objects so that they can be cleanly
unregistered when no more needed.

Unfortunately this all is certainly not a sufficient treatment of the
subject.


xelawho

unread,
Sep 16, 2011, 11:34:14 AM9/16/11
to Google Maps JavaScript API v3
as far as I am aware, the recommended procedure is to create one
infowindow and change its content and position with setContent and
setPosition (unless you want multiple infowindows showing
simultaneously).

from what I can tell, overriding an infowindow's contents removes the
previous contents from the DOM. But it means that once set, there will
always be one lot of contents in the DOM. It would have to be a very
large contents for it to make any real difference on most computers,
though.

dunno if that's relevant, but I thought I might mention it.
Reply all
Reply to author
Forward
0 new messages