Search code examples
.netcompact-frameworkmemory-management

Memory consumption in CF vs Full Framework


I was wondering if the memory consumption is different in the Full Framework vs the Compact Framework for types and classes that are compatible in between both. I would also like to know if I target an assembly for the compact framework (a .dll library), and reference it in the desktop machine. Will it use the types from the full framework or the compact. If it is the latter, I assume that the memory consumption should be the same but is it? My intuition is that compact framework types are simpler as they often have less methods, and many classes are missing. But are the memory representation per object the same? Does this depend on the architecture? (Running it on ARM vs x86 for example) Is there a resource where I can find more information about this topic?


Solution

  • I'd say it depends a whole lot on the specifics of what you're looking at. For example, if I have a simple object:

    public class Foo
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
    

    Then it's in-memory representation is going to be the same under either framework.

    If, however, I derive from a more complex class that is fundamentally different between the two frameworks, the results will then be different between the frameworks.

    If loaded in the FFx, it's going to use the FFx assemblies to instantiate the instances, so even though it was compiled for the CF, the FFx will load it under the FFX runtimes, not the CF.

    Processor architecture isn't going to matter, since these all compile to IL, which is processor-agnostic.

    Of course, since you're talking memory consumption under managed code, how the GC works is a big factor too, and they work differently in the CF and FFx, so the footprint can be different for identical classes over time between the two framework all depending on usage patterns.