Explicit concurrent copying GC freed 7041(512KB) AllocSpace objects error
I'm using Xamarin Forms framework for android and iOS mobile platform, on iOS devices it work's well but in Android when going on a specific page app shut down.
I got this error : Explicit concurrent copying GC freed 7041(512KB) AllocSpace objects
Using breakpoint I noticed crash arrived executing this
var content = JsonConvert.SerializeObject(
newStorageUsers,
Formatting.None,
new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
I show you entire demo code
Page in which I got error
private readonly IStorageUserService _storageService
public MyPage(User user)
{
InitializeComponent();
...
_storageService = new StorageUserServiceImpl();
_storageService.StoreUser(user);
...
}
Service Interface
public interface IStorageUserService
{
void StoreUser(User user);
}
Service Implementation
public class StorageUserServiceImpl : IStorageUserService
{
private string _usersPathFile = Path.Combine(App.GetPackagePath(), "users.txt");
public StorageUserServiceImpl()
{
if (!File.Exists(_usersPathFile))
{
_createUsersFile();
}
}
private void _createUsersFile()
{
var file = File.Create(_usersPathFile);
file.Close();
}
public void StoreUser(User user)
{
var currentStorage = GetStorageUsers();
List<StorageUser> newStorageUsers = new List<StorageUser>() { };
if (currentStorage != "" && currentStorage != "[]")
{
newStorageUsers = JsonConvert.DeserializeObject<List<StorageUser>>(currentStorage);
}
var storageUser = new StorageUser()
{
Infos = user,
CreationDate = Helper.DateFormatter.NowDateTime()
...
};
newStorageUsers.Add(storageUser);
var content = JsonConvert.SerializeObject(
newStorageUsers,
Formatting.None,
new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
_store(newStorageUsers, content);
}
private void _store(List<StorageUser> newStorageUser, string content)
{
// breakpoint can't be triggered there because app shut down with logs
File.WriteAllText(_usersPathFile, content);
}
}
public void StoreUser(User user)
{
var currentStorage = GetStorageUsers();
List<StorageUser> newStorageUsers = new List<StorageUser>() { };
if (currentStorage != "" && currentStorage != "[]")
{
newStorageUsers = JsonConvert.DeserializeObject<List<StorageUser>>(currentStorage);
}
var storageUser = new StorageUser()
{
Infos = user,
CreationDate = Helper.DateFormatter.NowDateTime()
...
};
newStorageUsers.Add(storageUser);
var content = JsonConvert.SerializeObject(
newStorageUsers,
Formatting.None,
new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
_store(newStorageUsers, content);
}
private void _store(List<StorageUser> newStorageUser, string content)
{
// breakpoint can't be triggered there because app shut down with logs
File.WriteAllText(_usersPathFile, content);
}
}
This service is used on several pages but I got this bug in only one page
After this message on logs :
Explicit concurrent copying GC freed 7041(512KB) AllocSpace objects, 2(264KB) LOS objects, 49% free, 4343KB/8687KB, paused 187us total 28.412ms
I got
Pending exception java.lang.StackOverflowError: stack size 8192KB ...
JNI DETECTED ERROR IN APPLICATION: JNI IsInstanceOf called with pending exception java.lang.StackOverflowError: stack size 8192KB ...
Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 8815 (om.myapp.app), pid 8815
've no more details of what happened and why, how can I fix this please?