Thanks Arothian.

I guess it's not a 'true' memory leak, in the sense that it does seem
to get reclaimed eventually. It's just that it's allocating more
memory than I would expect just to move a marker, and I would expect
that touching that much memory would impact performance.

As a test I've tried moving 10 markers dynamically, and memory
increases at around 5MB per second, but is reclaimed every 10 seconds
or so. This has a noticeable effect on performance though.

I've read that it's best to avoid relying on the garbage collection,
and instead reuse/recycle objects as much as possible. My initial code
moved the marker by allocating a new LatLng on each frame. For my test
code above I wanted to eliminate any allocations in my code, but since
a LatLng can't be changed after construction, I had to set the
position to a fixed location instead. A single LatLng shouldn't use
much memory (I presume it's just 16 bytes plus some overhead), but I
guess Marker.setLatLng() is allocating a lot of temporary objects
internally.

Anyway, I am going to try building a custom overlay as described at
http://groups.google.com/group/google-maps-api-for-flash/browse_thread/thread/52dc36c1a82ba119/22324304b29a1aed,
which will hopefully give me better control over the memory use.

Thanks,
Saxon


On Mar 27, 3:34 am, Arothian <[email protected]> wrote:
> Memory leaks are pretty hard to detect in flex. I would be concerned
> if the memory continued to leak after a significant time duration.
> Flex's garbage collection only happens during the allocation phase.
>
> See the following link for more info on gc in flex:
>
> http://blogs.adobe.com/aharui/2007/03/garbage_collection_and_memory.html
>
> On Mar 26, 10:41 am, Saxon <[email protected]> wrote:
>
>
>
> > Thanks Pamela.
>
> > It's compiled with a target frame rate of 30 fps, and I was just using
> > task manager.
>
> > It seems to be a bit unpredictable - today it is working fine for me
> > in FF3, but I still get the problem in IE7.
>
> > I've uploaded it tohttp://test.saxon.cx/test1/incase it's a
> > difference in compilation settings. The source there contains a
> > FlashDevelop 3.00 RC2 project.
>
> > According 
> > tohttp://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15507
> > I have version 10.0.22.87 of Flash (non-debug).
>
> > The memory does seem to be reclaimed every so often, after about 30 to
> > 75 MB has been allocated. It might just be that the garbage collector
> > isn't working very well, but 500k per second at 30fps = about 16k
> > allocated per marker move, which seems like a lot?
>
> > Thanks,
> > Saxon
>
> > On Mar 26, 12:00 am, pamela fox <[email protected]> wrote:
>
> > > Hi Saxon-
> > > I'm running that code in FF3 on Windows, and am not seeing any significant
> > > increased memory usage using Windows Task Manager.
>
> > > How are you monitoring the memory, and should I be doing something
> > > particular to run this at 30 FPS?
>
> > > - pamela
>
> > > On Tue, Mar 24, 2009 at 12:38 AM, Saxon <[email protected]> wrote:
>
> > > > Hi,
>
> > > > I want to be able to move a marker dynamically, but calling
> > > > Marker.setLatLng() seems to leak memory when I call it repeatedly.
>
> > > > The following cut down example mxml leaks about 500k per second, when
> > > > run at 30fps:
>
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <mx:Application
> > > >        xmlns:mx="http://www.adobe.com/2006/mxml";
> > > >        layout="absolute"
> > > >        enterFrame="onEnterFrame(event)">
> > > >        <maps:Map
> > > >                xmlns:maps="com.google.maps.*"
> > > >                id="map"
> > > >                mapevent_mapready="onMapReady(event)"
> > > >                mapevent_mappreinitialize="onMapPreinitialize(event)"
> > > >                width="640"
> > > >                height="480"
> > > >                key="my-api-key"/>
> > > >        <mx:Script>
> > > >                <![CDATA[
> > > >                        import com.google.maps.LatLng;
> > > >                        import com.google.maps.MapType;
> > > >                        import com.google.maps.MapOptions;
> > > >                        import com.google.maps.overlays.Marker;
>
> > > >                        private var marker:Marker = null;
>
> > > >                        private var mapCentre:LatLng = new 
> > > > LatLng(-33.8804,
> > > > 151.1912);
>
> > > >                        private function
> > > > onMapPreinitialize(event:Event):void
> > > >                        {
> > > >                                var mapOptions:MapOptions = new
> > > > MapOptions();
> > > >                                mapOptions.zoom = 20;
> > > >                                mapOptions.center = mapCentre;
> > > >                                mapOptions.mapType =
> > > > MapType.SATELLITE_MAP_TYPE;
> > > >                                this.map.setInitOptions(mapOptions);
> > > >                        }
>
> > > >                        private function onMapReady(event:Event):void
> > > >                        {
> > > >                                marker = new Marker(mapCentre);
> > > >                                this.map.addOverlay(marker);
> > > >                        }
>
> > > >                        private function onEnterFrame(event:Event):void
> > > >                        {
> > > >                                if (marker != null)
> > > >                                        marker.setLatLng(mapCentre);
> > > >                        }
> > > >                ]]>
> > > >        </mx:Script>
> > > > </mx:Application>
>
> > > > The leak occurs in both IE7 and firefox 3.
>
> > > > Is it something I am doing wrong?
>
> > > > Thanks,
> > > > Saxon- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API For Flash" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-maps-api-for-flash?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to