Exception of type 'System.OutOfMemoryException'

Posts   
 
    
Dhruvi
User
Posts: 3
Joined: 01-Dec-2016
# Posted on: 01-Dec-2016 13:59:24   

I have an application built on .NET Framework 3.5, LLBLGen Pro V2.6

There is an entity whose repeated add action is causing OutOfMemoryException. Any pointers to why this might be happening and how to resolve it would be very helpful.

Thanks.

Stacktrace Error: Source: mscorlib Message: Exception of type 'System.OutOfMemoryException' was thrown. Type: System.OutOfMemoryException StackTrace: at System.Collections.Generic.List1.set_Capacity(Int32 value) at System.Collections.Generic.List1.EnsureCapacity(Int32 min) at System.Collections.Generic.List1.Add(T item) at SD.LLBLGen.Pro.ORMSupportClasses.EntityRelation.AddEntityFieldPair[TEntityField](TEntityField primaryKeyField, TEntityField foreignKeyField) at Freedom.Data.DataAccess.RelationClasses.BreedColourRelations.get_BreedEntityUsingBreedId() in D:\Projects\Freedom\v12.24\Freedom\Freedom.Data.DataAccess\DatabaseGeneric\RelationClasses\BreedColourRelations.cs:line 51 at Freedom.Data.DataAccess.EntityClasses.BreedColourEntity.DesetupSyncBreed(Boolean signalRelatedEntity, Boolean resetFKFields) in D:\Projects\Freedom\v12.24\Freedom\Freedom.Data.DataAccess\DatabaseGeneric\EntityClasses\BreedColourEntity.cs:line 491 at Freedom.Data.DataAccess.EntityClasses.BreedColourEntity.SetupSyncBreed(IEntity2 relatedEntity) in D:\Projects\Freedom\v12.24\Freedom\Freedom.Data.DataAccess\DatabaseGeneric\EntityClasses\BreedColourEntity.cs:line 501 at Freedom.Data.DataAccess.EntityClasses.BreedColourEntity.SetRelatedEntity(IEntity2 relatedEntity, String fieldName) in D:\Projects\Freedom\v12.24\Freedom\Freedom.Data.DataAccess\DatabaseGeneric\EntityClasses\BreedColourEntity.cs:line 235 at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase21.PerformSetRelatedEntity(TEntity entity) at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore1.PerformAdd(T item) at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore1.Add(T item) at Freedom.Data.DataAccess.EntityClasses.BreedEntity.SetRelatedEntityProperty(String propertyName, IEntity2 entity) in D:\Projects\Freedom\v12.24\Freedom\Freedom.Data.DataAccess\DatabaseGeneric\EntityClasses\BreedEntity.cs:line 171 at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.SD.LLBLGen.Pro.ORMSupportClasses.IEntityCore.SetRelatedEntityProperty(String propertyName, IEntityCore entity) at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceCore.MergeNormal(IEntityCollectionCore rootEntities, IPrefetchPathElementCore currentElement, Boolean rootEntitiesArePkSide) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, Boolean forceParameterizedPPath) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath) at Freedom.Business.Service.AbstractProviderBase1.OnGetEntityCollection(DataAccessAdapter adapter, EntityCollection1 entities, IRelationPredicateBucket additionalFilters, Int32 MaxResults, SortExpression DefaultSort, IPrefetchPath2 DefaultPrefetch) at Freedom.Business.Service.AbstractProviderBase`1.GetEntityCollection(IRelationPredicateBucket additionalFilters) at Freedom.Business.Service.Common.BreedLookupProvider.GetBreed(Int64 speciesId) at Freedom.Presentation.WindowsUI.Forms.ClientsPets.PetForm.PopulateForm() in D:\Projects\Freedom\v12.24\Freedom\Freedom.Presentation.WinUI\Forms\ClientsPets\PetForm.cs:line 542

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 01-Dec-2016 16:10:27   

It seems like a collection resize issue, how many is being fetched and inserted in the collection?

Dhruvi
User
Posts: 3
Joined: 01-Dec-2016
# Posted on: 02-Dec-2016 14:37:35   

Hello Walaa, thanks for the response. It is some 18000 records.

/// <summary>Returns a new IEntityRelation object, between BreedColourEntity and BreedEntity over the m:1 relation they have, using the relation between the fields:
    /// BreedColour.BreedId - Breed.BreedId
    /// </summary>
    public virtual IEntityRelation BreedEntityUsingBreedId
    {
        get
        {
            IEntityRelation relation = new EntityRelation(SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToOne, "Breed", false);
            relation.AddEntityFieldPair(BreedFields.BreedId, BreedColourFields.BreedId);
            relation.InheritanceInfoPkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("BreedEntity", false);
            relation.InheritanceInfoFkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("BreedColourEntity", true);
            return relation;
        }
    }

Its throwing an exception on the Get Operation

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 03-Dec-2016 10:33:49   

please make sure you run on the latest .NET 3.5 service pack, as these out of memory exceptions are often caused by a .net bug. It's not our code, for 18K records memory shouldn't be a problem (unless they're 1GB in size each of course wink )

Frans Bouma | Lead developer LLBLGen Pro
Dhruvi
User
Posts: 3
Joined: 01-Dec-2016
# Posted on: 05-Dec-2016 11:57:39   

Hello Otis,

Thanks for the response.

The code is running on the latest 3.5 service pack. This is peculiar because its failing after repeated add action. So it works Okay for adding 10 entities and then fails on the 11th add.

Still looking for pointers,

Many thanks Dhruvi

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 05-Dec-2016 12:24:36   

the crash happens in a List<T>.Add(), which is initialized with its default constructor, so there's little else going on than that.

Is memory low when this happens? Does it happen all the time at the exact same point?

Also please check this answer: http://stackoverflow.com/questions/13520956/i-hit-an-outofmemoryexception-with-liststring-is-this-the-limit-or-am-i-miss

Frans Bouma | Lead developer LLBLGen Pro