I have recently tested the CachingStrategy for a ListView in a Xamarin Forms App with 1000 items in the list. List items are being created from a data template of ViewCell. I Tried using RecycleElement option for CachingStrategy.
When I did profiling, using Xamarin Profiler, for Android App deployed on Xamarin Anroid Player (emulator) I noticed that when I scroll through the list the memory allocation doesn't increase (on allocations summary tab). But, when I did profiling for iPhone App on emulator, I noticed that no data is being displayed on Allocations Summary tab. So I captured some snapshots while scrolling through the list and noticed whenever I scroll through the list (up or down), the memory allocation keeps increasing.
Why RecycleElement is not working for iOS (iPhone)?
I am using Mac for development.
Here are my tools:
=== Xamarin Studio ===
Version 5.10.1 (build 3)
Installation UUID: 7ae992a3-b710-4297-ba1d-0c519fbb2ea8
Runtime:
Mono 4.2.1 (explicit/6dd2d0d)
GTK+ 2.24.23 (Raleigh theme)
Package version: 402010102
=== Xamarin.Profiler ===
Version: 0.24.0.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
=== Apple Developer Tools ===
Xcode 7.1.1 (9081)
Build 7B1005
=== Xamarin.iOS ===
Version: 9.2.1.54 (Enterprise Edition)
Hash: eb4c1ef
Branch: master
Build date: 2015-12-01 02:12:30-0500
=== Xamarin.Android ===
Version: 6.0.0.34 (Enterprise Edition)
Android SDK: /Users/haider/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
4.0.3 (API level 15)
4.4 (API level 19)
5.0 (API level 21)
5.1 (API level 22)
6.0 (API level 23)
SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.1 rc1
SDK Build Tools Version: 23.0.2
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
=== Xamarin Android Player ===
Version: 0.6.5
Location: /Applications/Xamarin Android Player.app
=== Xamarin.Mac ===
Version: 2.4.0.109 (Starter Edition)
=== Build Information ===
Release ID: 510010003
Git revision: f2021a209d66d49cbc0649a6d968b29040e57807
Build date: 2015-12-01 10:43:40-05
Xamarin addins: dfd4f5103e8951edbc8ac24480b53b53c55e04ff
Build lane: monodevelop-lion-cycle6-baseline
=== Operating System ===
Mac OS X 10.11.1
Darwin Haiders-MacBook-Pro.local 15.0.0 Darwin Kernel Version 15.0.0
Sat Sep 19 15:53:46 PDT 2015
root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64
Here's A Few Things To Check
In the Xamarin Profiler, ensure that you are only looking for the custom ViewCell class, and take multiple snapshots to trigger the garbage collector. It may be something else that is causing the memory leak if the number of ViewCells is not increasing. If the number of ViewCells is increasing, move on to suggestions 2 & 3, below. Xamarin Profiler ViewCell example
In the ViewCell code, make sure to override OnBindingContextChanged() and set the controls' properties in OnBindingContextChanged(), rather than in the ViewCell's constructor. I added some sample code below that shows how to implement the ListViewCachingStrategy.RecycleElement strategy using a custom ViewCell.
If you are subscribing an Event Handler for the ViewCell (to add a Context Action for example), make sure to subscribe the Event Handler in the OnAppearing() method of the ViewCell class and unsubscribe the Event Handler in the OnDisappearing() method of the ViewCell class. I've included a comment in the example ViewCell code below.
ListView Using RecycleElement
ListView = new ListView(ListViewCachingStrategy.RecycleElement)
{
DataTemplate(typeof(CustomViewCell))
};
ViewCell
public class CustomViewCell : ViewCell
{
Label _myLabel;
MenuItem _deleteAction;
public CustomViewCell()
{
_myLabel = new Label();
View = _myLabel;
}
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
_myLabel.Text = "";
var item = BindingContext as MyModel;
if (item != null)
{
_myLabel.Text = item.Text;
}
}
protected override void OnAppearing()
{
base.OnAppearing();
//Subscribe ViewCell Event Handlers
_deleteAction.Clicked += HandleDeleteClicked;
ContextActions.Add(_deleteAction);
}
protected override void OnDisappearing()
{
base.OnDisappearing();
//Unsubscribe ViewCell Event Handlers
_deleteAction.Clicked -= HandleDeleteClicked;
ContextActions.Remove(_deleteAction);
}
void HandleDeleteClicked(object sender, EventArgs e)
{
//Code to handle when the delete action is tapped
}
}
ViewCell Model
public class MyModel
{
[PrimaryKey]
public int ID { get; set; }
public string Text { get; set; }
}
Related
I'm trying to deploy a stream using Java DSL.
Here the code that creates stream (fluent style)
private void create() {
builder
.name(this.STREAM_NAME)
.source(source)
.sink(sink)
.create();
}
deployment method
private void deploy() {
dataFlowOperations.streamOperations().deploy(this.STREAM_NAME, new HashMap());
waitForStatus("deployed");
}
and a method that creates a bean for source application
#Bean
public StreamApplication source() {
return new StreamApplication("httpsource")
.addProperty("app.httpsource.version", "0.0.17")
.addProperty("spring.cloud.dataflow.httpsource.validation.schema", this.properties.getHttpSource().getJsonSchema());
}
I first trigger create method, then deploy. The problem is - I want to set application version to 0.0.17 for httpsource application, but final pod that is deployed for this app has image version equal to default version 0.0.1. Is it possible to set application version with Java DSL?
When deploying streams/tasks, optionally, you can pass in the version parameters as part of the deployment properties. Specifically, for versions, you'd pass them with the version.<APP_NAME> convention.
The DataflowIT presents such test combinations (see: sample); feel free to use it for reference. We rely on these tests for IT and as well as end-to-end Acceptance Tests.
I want to download an artifact with Azure DevOps Services API.
While programing with C#, I choose to use Microsoft.TeamFoundationServer.Client SDK, Version: 16.153.0 as a tool.
I am sure I have the artifact.
But After I use
BuildHttpClient::GetArtifactContentZipAsync(project: "XXX", buildId: buildid, artifactName: "XXX")
to get zip stream. I get exception with a message like :
The requested version \"5.1\" of the resource is under preview. The -preview flag must be supplied in the api-version for such requests. For example: \"5.1-preview\"
It seems I use the wrong version of API, but I really didn't see any API to set this version to "5.1-preview".
Is there a way to solve this problem? Or should I use an older version of TFS SDK?
I tested with the 15.131.1 version of Microsoft.TeamFoundationServer.Client SDK and it works well , but trying the 16.153.0 version and it failed .
Sample code:
static readonly string TFUrl = "https://dev.azure.com/OrgName/";
static readonly string UserPAT = "PAT";
static void Main(string[] args)
{
try
{
int buildId = xx; // update to an existing build definition id
string artifactName = "drop"; //default artifact name
// string project = "projectName";
ConnectWithPAT(TFUrl, UserPAT);
Stream zipStream = BuildClient.GetArtifactContentZipAsync(buildId, artifactName).Result; //get content
using (FileStream zipFile = new FileStream(#"C:\MySite\test.zip", FileMode.Create))
zipStream.CopyTo(zipFile);
Console.WriteLine("Done");
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
if (ex.InnerException != null) Console.WriteLine("Detailed Info: " + ex.InnerException.Message);
Console.WriteLine("Stack:\n" + ex.StackTrace);
}
}
Thanks for Hugh's answer. Maybe there is something wrong with the SDK of version 16.153.0.
For some reason, I should use a new version SDK, so I choose to bypass the API and download the artifact by myself.
Firstly, I use BuildHttpClient::GetArtifactContentZipAsync to get an object of struct BuildArtifact.
Then I find the download link of artifact in BuildArtifact.Resource.DownloadUrl.
Finally I get the resource from this link.
In this way, I should handle some details like Auth/Httpdownload by myself. But anyway I get what I want.
Hope to work in the next version of TFS SDK.
I've seen solutions to doing this with Xcode and even Xamarin Studio, but nothing with Visual Studio.
Ideally, I'd like for every single build of the project to auto-increment the CFBundleVersion value within the Info.plist file.
<key>CFBundleVersion</key>
<string>9</string>
I don't even know where to start and haven't been able to find an article / blog post / tutorial on anything that includes Visual Studio.
Is this possible?
Just wanted to add that I am using Visual Studio 2015 on Windows 8.1.
Being in the same boat as you, as in not finding a proper solution, I decided to create my own. Maybe better late than never! :)
In my case I used the very useful Automatic Versions Settings tool (available on NuGet) to automatically update my assembly info, but wanted that to also update the Info.plist information as that's what HockeyApp uses to track and notify of new releases.
In the end, I kludged together a minimal C# program, which reads AssemblyInfo.cs, grabs the version info from there and edits the Info.plist XML file and writes it back.
It'd be a 20 line program if I hadn't put in a lot of paranoid checks, so as not to risk mangling Info.plist irretrievably (and even then it creates a backup of that file).
The "magic" comes down to two methods, the first one which I found here on SO:
Read AssemblyInfo.cs:
private static string GetVersionFromAssemblyInfo(string infile)
{
var version = String.Empty;
var readText = File.ReadAllLines(infile);
var versionInfoLines = readText.Where(t => t.Contains("[assembly: AssemblyVersion"));
foreach (var item in versionInfoLines)
{
version = item.Substring(item.IndexOf('(') + 2, item.LastIndexOf(')') - item.IndexOf('(') - 3);
}
return version;
}
Edit Info.plist, where the first 3 elements of the assembly info tuple becomes the CFBundleShortVersionString and the last element becomes CFBundleVersion which HockeyApp uses for build number.
The wonkiness in the LINQ is due to the slight weirdness of Apple's way of presenting the key/value pairs in that file:
private static bool SetVersionInInfoPlist(string infoplistFile, string version, string number)
{
var xelements = XDocument.Load(infoplistFile);
var dict = from el in xelements.Root?.Elements() select el;
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (dict == null) return false;
var cfshortversion =
from el in dict.Descendants("key")
where el.Value == "CFBundleShortVersionString"
select el.ElementsAfterSelf().FirstOrDefault();
;
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (cfshortversion == null) return false;
cfshortversion.FirstOrDefault()?.SetValue(version);
var cfversion =
from el in dict.Descendants("key")
where el.Value == "CFBundleVersion"
select el.ElementsAfterSelf().FirstOrDefault();
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (cfversion == null) return false;
cfversion.FirstOrDefault()?.SetValue(number);
// Make backup
try
{
File.Copy(infoplistFile, $"{infoplistFile}-backup", true);
}
catch (Exception)
{
Console.WriteLine($"Failed to create backup of {infoplistFile}. Will not edit.");
return false;
}
try
{
using (StringWriter sw = new StringWriter())
{
using (XmlWriter xWrite = XmlWriter.Create(sw))
{
xelements.Save(xWrite);
}
}
xelements.Save(infoplistFile);
}
catch (Exception)
{
Console.WriteLine($"Failed to save the edited {infoplistFile}.");
return false;
}
Console.WriteLine($"Successfully edited and saved new {infoplistFile}.");
return true;
}
EDIT: I should have also added that I use Bamboo for CI and build automation. This program therefore becomes a capability for the remote build agent and then I can add it as a Task in the Bamboo build Plan.
This code does not work anymore.
String getHomePath() {
var home = Platform.environment['HOME'];
if(home != null) {
return pathos.normalize(home);
} else {
return null;
}
}
Breaking on exception: Class '_LocalLibraryMirror'
has no instance getter 'classes'.
Does this mean that the library "dart: mirrors" redesigned and the package "pathos" does not account for these changes?
Also, I'm surprised that package "pathos" uses "dart: mirrors" to determine in which environment it used (browser or standalone).
Here is the same problem mentioned https://github.com/angular/angular.dart/pull/408
Update to 1.1.0-dev.5.6 solved it for them.
You could check with pub upgrade if there is any updated package version that is not pulled due to version constraints and use dependency_overrides to force the newest package version.
I have VS .NET 2010 installed, and a class library targeting .NET 3.5. The simple C# fragment below generates verifiable IL under .NET 4.0's peverify, but the IL does not verify using .NET 3.5's peverify.
Were there any peverify bugs fixed in this transition?
public static bool IsGenericTypeInstance(this Type typ)
{
return typ.IsGenericType && !typ.IsGenericTypeDefinition;
}
public static IEnumerable<Type> GetAllGenericArguments(this Type type)
{
return type.IsGenericTypeInstance()
? type.GetGenericArguments()
.SelectMany(x => x.IsGenericTypeInstance()
? GetAllGenericArguments(x)
: new[] { x })
: Enumerable.Empty<Type>();
}
The error generated is:
Error 26 [Sasa.dll : Sasa.Types::<GetAllGenericArguments>b__0]
[offset 0x0000001C][found ref 'System.Collections.IEnumerable']
[expected ref 'System.Collections.Generic.IEnumerable`1[System.Type]']
Unexpected type on the stack.
I'm obviously a little concerned since I'm explicitly targeting .NET 3.5, and I don't want runtime verification errors on this platform.