Bug 4220 - new sbyte[] causes memory leak
Summary: new sbyte[] causes memory leak
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 4.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-04-04 02:45 UTC by Paul Sinnema
Modified: 2012-04-04 04:39 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Paul Sinnema 2012-04-04 02:45:15 UTC
Hi,

I'm trying to implement the ZXing library for scanning of barcodes. During my implementation I got several out of memory crashes. I started to investigate the problem and it seems that it is caused by the sbyte allocation. I've written a small test set that can prove my point. You'll find it below. It happens in a MonoTouch iPhone Application (so the project type is MonoTouch/iPhone/Empty Project). Then cut and paste the code below.

Regards
Paul Sinnema



using System;
using System.Diagnostics;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace SByteTest
{
	[Register ("AppDelegate")]
	public partial class AppDelegate : UIApplicationDelegate
	{
		UIWindow window;

		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			window = new UIWindow (UIScreen.MainScreen.Bounds);
			
			window.MakeKeyAndVisible ();
			
			for (;;)
			{
				using (var alloc = new AllocBytes())
				{
					alloc.Test();
				}
			}
			
			return true;
		}
		
		private static int Counter;
		
		public class AllocBytes : IDisposable
		{
			private sbyte[] testBytes;
		
			public void Test ()
			{
				Debug.WriteLine(Counter++);
			
				testBytes = new sbyte[1024000];
			}

			public void Dispose ()
			{
				testBytes = null;
			}
		}
	}
}
Comment 1 Paul Sinnema 2012-04-04 03:50:23 UTC
I just discovered that the crash it causes is not the OutOfMemoryException but a timeout. The device log says the following.

Apr  4 09:45:53 iPhone-van-arno SpringBoard[29] <Warning>: SByteTest failed to launch in time
Apr  4 09:45:53 iPhone-van-arno SpringBoard[29] <Warning>: Forcing crash report of SByteTest[12501]...
Apr  4 09:45:53 iPhone-van-arno SpringBoard[29] <Warning>: Finished crash reporting.
Apr  4 09:45:53 iPhone-van-arno com.apple.launchd[1] (UIKitApplication:sbytetest[0x660f][12501]) <Notice>: (UIKitApplication:sbytetest[0x660f]) Exited: Killed: 9
Apr  4 09:45:53 iPhone-van-arno SpringBoard[29] <Warning>: Application 'SByteTest' exited abnormally with signal 9: Killed: 9

I guess I need to do some more testing. I'll try and enhance the App.
Comment 2 Paul Sinnema 2012-04-04 04:37:41 UTC
After carefully testing this in a view I must conclude that my first assumption is wrong. The byte does not seem to be the problem.