Subscribe Now: Feed Icon

Monday, February 14, 2011

mscorlib: Could not resolve this reference

I have decided to split my post “Rebuild All failed without any errors (Silverlight)” since for one of the build problems I found a solution.

So, to recap I have changed the Build Details: Options->Projects and Solutions->Build and Run->MSBuild project build output verbosity: from Minimal to Detailed. And found this message:

Dependency "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e".
    Could not resolve this reference. Could not locate the assembly "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

Required by "System.Windows.Interactivity".

I actually questioned myself – How can the build not find mscorlib?

 

Restarting the VS didn’t solve this problem, but looking deeper into the Detailed Build Report did. I found this:

There was a conflict between "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e".
    "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was chosen because it was primary and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" was not.
    References which depend on "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" [C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll].
        C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll
         …

References which depend on "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" [].
        C:\Projects\Libraries\System.Windows.Interactivity.dll
          Project file item includes which caused reference "C:\Projects\Libraries\System.Windows.Interactivity.dll".
            System.Windows.Interactivity

And fixed the problem. Apparently my team’s web project (for some unknown reason) referenced “System.Windows.Interactivity.dll” which is a Silverlight Dll – I still don’t understand why it didn’t appear as either a warning nor an error.

At least it gave me a reason to go over my project references with Resharper “Find code dependent on module” and removed those references that are not used (something I hate to do, the guys at Resharper have actually put a vote on something to fix this – please enter and vote).

 

Keywords: Silverlight, reference, VS2010, Resharper

Rebuild All failed without any errors (Silverlight)

This is actually a call for help since the only fix I found was restarting Visual Studios, and I don’t like those kind of fixes.

A picture is worth more than mere words:

VS-rebuild-failed-no-errors

As you can see Rebuild All failed but the Error List only contains 10 Warnings, going to the Output window:

========== Rebuild All: 25 succeeded, 5 failed, 0 skipped ==========

But no reference to the errors…

 

The first thing I tried was building the projects until I got to the problematic Project, it was my Silverlight Application project but the weird thing here was:

========== Build: 4 succeeded or up-to-date, 8 failed, 0 skipped ==========

Rebuilding the solution => 5 failed, building a single project inside that solution => 8 failed – WTF? building the projects referenced by that single project and they all pass…

 

The second thing I tried was changing the Build Details: Options->Projects and Solutions->Build and Run->MSBuild project build output verbosity: from Minimal to Normal (I have decided to do it gradually otherwise it’s like drowning in information). Still no errors so I moved it up to Detailed, this time I had some weird entries like this:

Dependency "PostSharp.Public, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7".
    Could not resolve this reference. Could not locate the assembly "PostSharp.Public, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

The weird thing is that non of the projects I am building use PostSharp. But a reference that I am using uses this reference on the server side (not related to the Silverlight build…).

Other references that had the same error were System, mscorlib, System.Windows and WPFToolkit. How can the build not find mscorlib? (I actually found why it didn’t find mscorlib, you can read about it here – has nothing to do with the errors).

 

Restarting Visual Studios fixes the problem the build errors but the Dependencies are still missing… The good thing is I saved the detailed build that failed and compared the files. The first difference was their size the failed was ~0.5MB less. Other differences:

Failed:

Target "GetNativeManifest" skipped. Previously built successfully.
Building with tools version "4.0".
Target "_CheckForInvalidConfigurationAndPlatform" skipped. Previously built successfully.
Target "GetNativeManifest" skipped. Previously built successfully.
Building with tools version "4.0".
Target "_CheckForInvalidConfigurationAndPlatform" skipped. Previously built successfully.
Target "GetNativeManifest" skipped. Previously built successfully.

Passed:

Target "GetNativeManifest" in file "c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets" from project "C:\Projects\MapControl.csproj" (entry point):
Done building target "GetNativeManifest" in project "MapControl.csproj".
Building with tools version "4.0".
Target "_CheckForInvalidConfigurationAndPlatform" skipped. Previously built successfully.
Target "GetNativeManifest" in file "c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets" from project "C:\Projects\PropertiesControl.csproj" (entry point):
Done building target "GetNativeManifest" in project "PropertiesControl.csproj".
Building with tools version "4.0".
Target "_CheckForInvalidConfigurationAndPlatform" skipped. Previously built successfully.
Target "GetNativeManifest" in file "c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets" from project "C:\Projects\Components.csproj" (entry point):
Done building target "GetNativeManifest" in project "Components.csproj".

Some more lines that only appear in passed:

Using "CreateMetadataAssemblyTask" task from assembly "c:\Program Files\Microsoft Visual Studio 10.0\\Common7\IDE\Extensions\Microsoft\RiaTools\Intellisense\Microsoft.VisualStudio.ServiceModel.DomainServices.Intellisense.dll".

Using "CreateRiaClientFilesTask" task from assembly "C:\Program Files\Microsoft SDKs\RIA Services\v1.0\Libraries\Server\Microsoft.ServiceModel.DomainServices.Tools.dll".

Using "UpdateRiaTempPETask" task from assembly "c:\Program Files\Microsoft Visual Studio 10.0\\Common7\IDE\Extensions\Microsoft\RiaTools\Intellisense\Microsoft.VisualStudio.ServiceModel.DomainServices.Intellisense.dll".

Another change, failed:

Task "MSBuild" skipped, due to false condition; ('@(_MSBuildProjectReferenceExistent)' != '' and '$(_GetChildProjectCopyToOutputDirectoryItems)' == 'true' and '%(_MSBuildProjectReferenceExistent.Private)' != 'false' and '$(UseCommonOutputDirectory)' != 'true') was evaluated as ('' != '' and 'true' == 'true' and '' != 'false' and 'false' != 'true').

Passed:

Task "MSBuild"
  Global Properties:
    Configuration=Debug
    Platform=AnyCPU
Building with tools version "4.0".

This change happened twice more with different projects.

 

Not sure what it means, I have my usual suspects though – ESRI and their Silverlight API since that was the last thing I changed in the Silverlight project… and there is also Resharper 6.0 EAP since it throw exceptions (1,2 and 3) every time the build failed (and now after VS restart it is calm). But for all I know it’s Visual Studio that has a lock on a file or something…

 

I just hate not knowing why things are working when I am sure they are not supposed to work.

Well it is not a one time thing, it happened again and my VS memory has reached 900MB (it didn’t even agree to copy the build output – out of memory)… And Resharper has started throwing those exceptions long before the build errors…

Does anyone else had this problem? know why? Please leave a comment…

 

Keywords: Build, Error, Silverlight

IceRocket Tags: ,,

Build Error: Using COM References in .Net 4.0

I found that several of my team’s projects had .Net 3.5 by mistake so I upgraded them and got this error:

Member 'Project.CadWorkspaceUtils.GetGeometries()' from assembly 'c:\Projects\Company\GIS\Framework\Server\Bin\Company.GIS.Core.Esri.dll' cannot be used across assembly boundaries because it contains a type which has a generic type parameter that is an embedded interop type.   

(it took me a while to find the cause because I also upgraded the ESRI WPF/Silverlight API references and I thought that something got removed from the framework)

CadWorkspaceUtils.GetGeometries() returns List<IGeometry> that are in a CAD file, that class sits in a .Net 3.5 project (I can’t upgrade that one yet because of constraints outside of my team).

The error was caused because in .Net 4.0 referencing COM Dlls has been upgraded with this option:

com-reference-dotnet-4

In .Net 4.0 the default is true whereas in .Net 3.5 the option does not exist. The error is fixed easily by changing the “Embed Interop Types” in the reference to false in the .Net 4.0 project.

 

But what does that option mean?

Type Embedding and Type Equivalence

Another major concern related to deployment of Office customizations was deployment of Primary Interop Assemblies (PIAs). Before .NET Framework 4 if the customization only used some of the interfaces and methods from the Interop Assemblies, the complete set of the Primary Interop Assemblies still had to be deployed. .Net Framework 4 addresses this in very elegant way. The C# and VB compilers provide a /link switch that embeds the types referenced from the Primary Interop Assemblies into the application assembly itself. , Type Equivalence in the CLR can understand these embedded types and link them to the appropriate types at runtime. With this the customization does not require deployment of the Primary Interop Assemblies on end-user computers.

Taken from here.

It means that the assembly types are inserted into the project assembly (without the original Dll).

As far as I can understand it the original type does not actually equals the embedded type – causing the build error.

 

Resources:

Why Should I Upgrade from .Net Framework 3.5 to .Net Framework 4 ? (Navneet Gupta)

CLR and DLR and BCL, oh my! - Whirlwind Tour around .NET 4 (and Visual Studio 2010) Beta 1

 

Keywords: build error, com, reference

IceRocket Tags: ,,

Following Blogs

Ever since 4.5 years ago when my team leader made me follow 3 blogs I have been an avid fan of reading blogs. I try to keep a system of 2/3 fun stuff and 1/3 development stuff just so I won’t loss interest. My blog list has changed over the years, I usually know when to quit following a blog – usually it’s 3 days after it becomes a chore reading that blog. Blogs that have a good chance of becoming a chore are either blogs with too many posts or blogs where you only get a summery of the post and you have to actually surf (shudder) to the post (and of course the content is important).

I use Google Reader for following blogs more because it actually became a social thing for me than that it is an easy system that can be used from everywhere (with an internet connection and a browser). Most of my friends use it and we share posts back and forth (for example a few days ago Rita shared this lovely post about abstract override, I am still in denial that it is possible in c#). I mostly share funny stuff like this (or Can you tell a coder from a cannibal?) but also development stuff like this.

So without further ado here is my blog list (as they are ordered in my account of Google Reader):

News-System:

Popular-Blogs: (fun stuff)

  • Google popular – long ago Google Reader had a popular tab I just added it’s feed for my Reader, just to make sure I read it all…
  • Mind Hacks – it is just amazing what the human mind is capable of…

ArcGis: (technical map related – not just ESRI)

Programming: (just guess)

Silverlight:

WPF:

.NET: (there are more…)

SQL: (much more…)

programming---good:

Programming-Joel: (yes, he gets a place of his own)

Friends: (teammates and team leaders)

programming---processed: (this was from the days I thought about going over all the posts from the start – thankfully it passed and all that remains today is the name of the category)

Programming-Hebrew:

Programming-found-while-surfing: (for blogs I found while searching for stuff)

Programming-good-webcasts: (for podcasts and webcasts)

Funny: (just for fun, almost done – are you excited?)

Followers – this is where I put all those people that follow me and I follow them

Quotes: (for the days I want to change my current quote in GTalk (right now it’s: "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - Martin Golding)

Japan: (for the crazy stuff, I am sorry but judge for yourselves if it’s crazy or not)

There is also my shared items if you want to follow it (warning some of them are in Hebrew):

 

I have more but most of them haven’t been updated in years, while others I consider deleting…

How did I find so many? I usually search for things on the web and if I like the blog I just copy it to my Reader in the category of “programming-found-while-surfing”…

When do I read them? Well I used to read them on the way to work on the train by caching them on my IPod, now I just read them between build, while running my unit tests or when I want to strangle the guy that programmed that $#!& of a framework  relax a bit…

I am told I am pretty crazy with the amount of blogs I follow (if you also think so then leave a comment)…

Monday, February 7, 2011

Silverlight Memory Leak, Part 2

Continued from part 1 (or what does VMMap give).

Before checking the memory with the application running (from just looking at Task Manager I know I have a problem there too), I actually wanted to see how the other programs look after the memory leak was solved.

 

Task manager (after going to lunch (last time the computer just died)):

memory-leak-after-task-manager

VMMap:

vmmap-after-memory-leak-timeline

It still show a lot of the memory as free but at least some of the memory is freed over time. It is still weird because Task manager shows ~100MB of memory used and this graph shows more. Because of that I decided to investigate Task Manager a bit more and view most of the memory related columns:

task-manager-after-woking-set-memory

I actually looked at “Memory (Private Working Set)” before (the default selected one and more correct one) and the timeline is with “Working Set (Memory)”. The difference between the two is that the second is the private working set (memory that can’t be shared) plus the memory that can be shared whereas the first is only the private memory that cannot be shared (at least according to this).

vmmap-after-memory-leak-space-fragmentation

It actually still have a large hole in the middle (the purple lines are images – unmanaged memory). But I already thought in the last post I might have a problem there.

vmmap-after-leak-main-ordered

This main window is still pretty much unreadable. Can anyone really read this?

Comparing it to the before state:

The bottom grid is unneeded – it is just too much data without any way to organize it. Using the default sorting might show you the holes in the memory but Address Space Fragmentation is much better at this.

The middle grid is the interesting grid, look at the Private WS (=Work Set) column (this is the memory private to your process at least according to this):

  1. Purple – image – weird the memory was halved, see *
  2. Blue – Mapped File – is still unused.
  3. Light blue – Shareable – is still unused.
  4. Orange – Heap – has grown by 150%, see *
  5. Green – Managed Heap – from ~350MB to ~40MB, fixed that problem
  6. Light orange – Stack – is unchanged and is too low for me to care for…
  7. Yellow – Private Data – is lower by ~30%, see *
  8. Brown – Page Table – is lower but it’s too low to care…

* It can actually be because the testing process wasn’t as long or with as many updates.

Back to VMMap main page, the top seems to be a graphical representation of the Committed column, Private column and Total WS Column (in the middle grid). Again it is irrelevant to us (no way of changing it to Private WS column).

 

 

One last warning if you are planning to use VMMap, then don’t use at startup the option of “Launch and Trace a new process” with IE:

vmmap-Launch-and-Trace-a-new-process-option

This option will launch with the process for the tab IE process not the IE process for the Silverlight Application(for more information on that look here (debugging and profiling being very similar…)). It is also the only way I found to activate the Call Tree and Trace buttons (bottom right of VMMap). The Heap Allocations button never worked for me…

So use this Task Manager knockoff (it gives you process name, PID, memory and user):

vmmap-view-a-running-process-option

I just chose the IE process with the most memory usage – I usually have only two (and if I got the wrong one I actually don’t have a memory problem, do I? Winking smile).

 

Until next time (this time I won’t say tomorrow since both my computer died (it’s still has problems) and our IT department decided to upgrade the systems over the weekend and nothing worked until they downgraded it back).

 

Resources:

Performance on Silverlight TV

Windows: What do the Task Manager memory columns mean?

Silverlight Tip of the Day #2– Attach to Process Debugging

 

Keywords: memory, vmmap, silverlight, memory leak

Sunday, February 6, 2011

Geographic Coordinates Systems

This is something I believe every GIS Programmer is supposed to know.

A few weeks ago I had some problem with Union of IPolyline into one IPolyline and someone who is from the company that provides support for ESRI products in our region tried to help me. We were in the middle of debugging and he noticed that the length of one of the original IPolline was something like 0.000001. He thought that the problem was that my line was too small – less than a CM long.

I was shocked that he could tell the length of the line, but then he explained himself and said that 0.01 was a CM – and then I was shocked for a different reason…

I knew where he got it wrong. He was used to working with a coordinate system like UTM WGS84 where the length of the lines is in meters. But I was working with GEO WGS84 where the coordinates are in degrees and the length of the lines is NOT in meters.

I believe it is very similar to the old mistake NASA once made where some of their spacecraft parts were made in CM and some in inches (see CNN: Metric mishap caused loss of NASA orbiter). At that time that mistake cost 125 million dollars. Mistakes in Geographic Coordinate can cost lives in a military assault where accurate coordinates are essential.

 

GEO Coordinates

GEO Coordinate (called also GCM=Geographic Coordinate System) use degrees of latitude and longitude to describe a location on the earth’s surface. The latitude lines are parallel to the the equator (between the North and South poles), The North pole has 90° and the South pool has -90° (the equator has 0°).

coordinate-system-latitude

(Not mine taken from Wikipedia)

The longitude lines run from the North pole to the South pole, only at the equator the distance between the lines is equal to the distance between the latitude lines. The degrees for the lines run from 0° to 180° for East or West (or 360° all around). The 0° line passes Greenwich, England.

coordinate-system-Longitude-and-Latitude

(Not mine from here)

coordinate-system-geo-figure

(Not mine from here)

 

UTM Coordinates

UTM Coordinates (Universal Transverse Mercator) on the other hand is a metric system that project the Earth’s spherical surface onto a two-dimensional plane. In one way of this system the globe is divided to 1200 tiles (maps in an atlas usually use this way of the system):

coordinate-system-utm-tiles

(Not mine from here)

In the other way the globe is divided to 60 zones (each zone has 6°) which are divided further to North and South (ESRI uses this way of the system):

coordinate-system-utm-36-zones

(Not mine from here)

Both this ways were devises because the metric distance in them is optimal

This is in Datum WGS84 you should be aware that there are other Datums.

When calculating a distance in UTM where the coordinates are not in the same tile the distance should be calculated to the border of the tile and then continue through the tiles until reaching the second point:

Coordinate-system-utm-distance

(Every different line in this drawing should be calculated independently)

 

So what’s the difference?

  • A distance between point in UTM (in the same tile) will be in meters, where as in GEO the distance is not as accurate since the degrees of longitude lines does not equal everywhere on earth.
  • A GEO coordinate of 61.44, 25.40 will be presented in UTM as 35V 414668 6812844.

 

How do I use the coordinate systems in code?

In arcObjects the coordinate systems are called Spatial References and are set in a property named SpatialReference in IGeometry.

GEO WGS84 Spatial Reference(one of the useful methods I have on my team’s application):

  1. public static ISpatialReference CreateWgsSpatialReference()
  2. {
  3.     SpatialReferenceEnvironment spatialReferenceEnvironment = new SpatialReferenceEnvironmentClass();
  4.     ISpatialReference wgs84SpatialReference =
  5.         spatialReferenceEnvironment.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
  6.     return wgs84SpatialReference;
  7. }

 

UTM WGS84 Spatial Reference for zone 14N:

  1. SpatialReferenceEnvironment spatialReferenceEnvironment = new SpatialReferenceEnvironmentClass();
  2.  ISpatialReference wgs84UtmSpatialReference =
  3.      spatialReferenceEnvironment.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_WGS1984UTM_14N);

 

You should note that there are many such spatial references in UTM WGS84, for example:

  1. esriSRProjCS_WGS1984UTM_55N = 32655,
  2. esriSRProjCS_WGS1984UTM_56N = 32656,
  3. esriSRProjCS_WGS1984UTM_57N = 32657,
  4. esriSRProjCS_WGS1984UTM_58N = 32658,
  5. esriSRProjCS_WGS1984UTM_59N = 32659,
  6. esriSRProjCS_WGS1984UTM_60N = 32660,
  7. esriSRProjCS_WGS1984UTM_1S = 32701,
  8. esriSRProjCS_WGS1984UTM_2S = 32702,
  9. esriSRProjCS_WGS1984UTM_3S = 32703,
  10. esriSRProjCS_WGS1984UTM_4S = 32704,

(Taken from ESRI reflected code)

 

A method that creates a point with GEO WGS84 coordinate system:

  1. public static IPoint CreatePoint(double x, double y)
  2. {
  3.     IPoint point = new PointClass { X = x, Y = y, SpatialReference = CreateWgsSpatialReference() };
  4.  
  5.     return point;
  6. }

 

I would like to thank Asafi Yosef (by far the best Geodesist that I know) for reviewing this post and correcting some of my mistakes.

 

Edit 27/03/2011: Found this nice link that show the distortions caused by different Coordinate Systems. If you want to see why GEO WGS84 is bad for distances then check it out.

 

Resources:

Geographic Coordinate System

Tissot's indicatrix

 

Keywords: ESRI, Coordinate system, Coordinate, Point, WGS84, GEO, UTM, IPoint, distance

Wednesday, February 2, 2011

Silverlight Memory Leak, Part 1

Yesterday my team leader told me he is pretty sure we have a memory leak in our application. The memory usage for the web browser just continued to grow without any end. And when using an environment with a lot of data that problem multiplied. I actually thought we had one after my computer came to a crawl when I forgot to close the browser…

 

The task manager view on my IE memory:

Task-manager-IE-memory

 

Well, first of all I found and downloaded Sysinternal’s VMMap, in order to see my memory map:

VMMap-my-memory-map

This window is totally unreadable to me, what about you?

Pressing F5 refreshes the view (and enables the Timeline button).

The colors are set by the middle table:

VMMap-memory-types

The bottom table can be played with like a regular grid (Dah!)

Pressing the Timeline button, starting timeline:

VMMap-start-timeline

Ending timeline:

VMMap-end-timeline

Something is a little weird here for me, at the bottom there is a view of all the memory usage of my Silverlight Application, in the middle there is just an empty space, and on the top there is the line (pink?) of the current memory usage. My take on this is that my Application is using less than 50MB of memory but has free memory locked in bubbles of used memory (like in the file system where you have Size and Size on Disk, Size on Disk >= Size). It is actually called fragmentation of the large heap you can read more about it here, here and here (the links can also be found at the bottom of this post).

So I decided to look at the Fragmentation View (under View in the menu):

VMMap-Fragmentation-View

I can see here what I thought happened: the free memory (white) is locked inside used memory.

 

At this stage in time (~700MB in task manager) my Windows 7 machine became unresponsive and I had to terminate the IE!

 

Next lets look at Ants Memory Profiler (I am using the trial version):

After installation I got a nice screen to enter my Silverlight application:

Ants-memory-silverlight-option

I waited for the memory to stabilized and then took a memory Snapshot (the graph in the middle show the memory status):

ants-memory-startup[5]

A summery I can actually follow:

ants-memory-summery-page

I took another snapshot and this time in the class list I could see the changes of the instances:

ants-class-list-snapshot-comparison

I found it useful to sort by Size Diff and Instance Diff.

 

Well at this point in time I decided to go to lunch and keep the profiler running. When I returned from lunch I noticed the memory spike and decided to take a snapshot – that was a mistake apparently because the computer became unresponsive and I had to kill it (or as I like to call it I had to “suffocate it with my bare hands” by pressing the shut down button until the computer “died” (shutdown) and then I turned it on).

 

First I decided to record a base line – not to do any action and see how the memory acts. If you haven’t guessed let me give you a hint: it goes up! (let me warn you though having 9 snapshots is 5 too much when saving the data – the computer just slows down and the hard drive is 2GBs less)

The timeline:

ants-baseline-timeline

(I am just a growing boy…)

Session overview:

ants-baseline-session-overview

(the only graph not in constant growth is Gen1 which means that almost no new objects are created and freed, those that are not freed move to Gen2)

Comparing snapshot 9 to snapshot 1

(25 minutes of hell) seen a growth of ~160MB

Memory Fragmentation:

ants-baseline-memory-fragmentation 

(why can’t I copy text in Ants?)

Most of the memory goes to the Gen2:

ants-baseline-memory-graph

Class list:

Ants-baseline-class-list

It seems the problematic class is CustomDependencyProperty, it also seems that all top three lines are connected (look at the Instance Diff column it has about the same number) and they are also the top rows in all the sorting options. By the way, looking at the top three lines in comparing snapshot 9 and 8 shown the same result (minus around 800K in Diff).

Well Instance Categorizer solved one mystery:

ants-baseline-instance-categorizer

(explains the exact same number of Instance Diff)

With String I found the culprit in Instance List you can see the values of the strings:

ants-baseline-string-instance-list

(without the 100 at the end of the string these are one of my ArcGIS Server layer’s field names)

It was because of a stupid mistake I did back when I knew nothing of Silverlight and decided to use my knowledge of regular ESRI code with the Silverlight API. I wrapped ESRI Graphic class with my own class, inherited from it and wrapped all the work with Attributes with property – until here all is well (using Attributes with strings is just evil). Then I had trouble with fields that were updated and the updates weren’t shown on the forms and my team leader suggested I use Dependency Properties so I just added it to the entities base class with DependencyProperty.Register and forgot about it till now.

The next bit of information is that we have a mechanism for automatically updating all the Feature Layers once (+/-X seconds (X is determined in the config)) there is a change in the layer.

The third bit of information is that we have a grid that shows updates to two of this layers and uses the wrapper entities to do that (getting the values for the rows/columns of the grid with properties).

Since the dependencies aren’t unregistered and the entities are recreated – the memory just grows and grows.

 

Current end result

Timeline:

ants-end-result-timeline

(it is still rising just slower, as you can see now the line is a bit more balanced.)

The size change between snapshot 1 and snapshot 4 is ~680KB (no MBs this time!)

Most of my memory is unmanaged (the same amount from last time):

ants-end-result-memory-graph

Session Overview:

ants-end-result-session-overview

(I still don’t like the unused space in the Large Object Heap Size but there is always tomorrow…)

Memory Fragmentation:

ants-end-result-memory-Fragmentation

(look at that it’s green with “No issues…”)

Class list:

ants-end-result-class-list

(no millions of objects – where did they go?)

Another sort of class list:

ants-end-result-class-list-live-sort

(would you look at that, this time there are different results)

By the way ants also gives advice about what the unmanaged memory could be. You should check it out.

 

It’s not the end, just the beginning… tomorrow I will check how the application uses the memory when it is run (not just refreshed every 30 seconds).

 

Continue in part 2

Resources:

Understanding Garbage Collection in .NET

MSDN, CLR Inside Out: Large Object Heap Uncovered

The Dangers of the Large Object Heap

Analyzing Silverlight Memory Usage: Part 1 – Obtaining Measurements

Ants - Checking unmanaged memory usage

 

Keywords: Silverlight, memory leak, ants, vmmap, DependencyProperty