I use iPhone 6 simulator in Xcode. After I add a simple UITextView in my view, I type some word in it. But I found some errors in console:
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextSaveGState: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextDrawLinearGradient: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextFillRects: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextFillRects: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextFillRects: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextSaveGState: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextDrawLinearGradient: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextFillRects: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextFillRects: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextFillRects: invalid context 0x0
And when I watch the memory use ,it increase very fast.But when I use iphone5 or iphone4.3 Simulator it will not appear.
Here is my code:
#import "ViewController.h"
#include <sys/sysctl.h>
#include <mach/mach.h>
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UITextView *textView=[[UITextView alloc] initWithFrame:CGRectMake(0,0,320,50)];
[self.view addSubview:textView];
[textView release];
NSTimeInterval timeInterval =5.0 ;
[NSTimer scheduledTimerWithTimeInterval:timeInterval
target:self
selector:#selector(handleMaxShowTimer:)
userInfo:nil
repeats:YES];
}
- (double)availableMemory
{
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(),HOST_VM_INFO,(host_info_t)&vmStats,&infoCount);
if(kernReturn != KERN_SUCCESS)
{
return NSNotFound;
}
return ((vm_page_size * vmStats.free_count) / 1024.0) / 1024.0;
}
- (double)usedMemory
{
task_basic_info_data_t taskInfo;
mach_msg_type_number_t infoCount = TASK_BASIC_INFO_COUNT;
kern_return_t kernReturn = task_info(mach_task_self(),
TASK_BASIC_INFO, (task_info_t)&taskInfo, &infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return taskInfo.resident_size / 1024.0 / 1024.0;
}
-(void)handleMaxShowTimer:(NSTimer *)theTimer
{
NSLog(#" use memory %f remain memory %f",[self usedMemory],[self availableMemory]);
}
#end
Your memory usage most likely isn't "increasing like crazy", you just happen to be looking at the total number of bytes allocated in instruments, which is meant to steadily increase. Use the actual leaks tool and it will even tell you the exact line of code the leaks occur at, and how much one particular function is contributing to the overall leakage.
As for the CG... Errors, drawing code needs to be done in a -drawRect: override, which is the only place you can get a stable non-NULL context to draw into.
Related
I want to read the text file into json. i have a text file with three lines.
While i tried to read using json .It returns all the 3 lines into one string.
Here is my code for your reference :
[System.Web.Mvc.HttpPost]
public JsonResult upload(HttpPostedFileBase file)
{
bool result = false;
StringBuilder strbuild = new StringBuilder();
try
{
if (file.ContentLength == 0)
throw new Exception("Zero length file!");
else
{
var fileName = Path.GetFileName(file.FileName);
var filePath = Path.Combine(Server.MapPath("~/Downloads"), fileName);
file.SaveAs(filePath);
if (!string.IsNullOrEmpty(filePath))
{
using (StreamReader sr = new StreamReader(Path.Combine(Server.MapPath("~/Downloads"), fileName)))
{
while (sr.Peek() >= 0)
{
strbuild.AppendFormat(sr.ReadLine());
}
}
}
}
}
catch (Exception)
{
result = false;
}
return new JsonResult()
{
Data = strbuild.ToString()
};
}
My Result is :
"HD-M-16-H-000001*1001*1 HD-M-16-H-000001*1001 HD-M-16-H-000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F- 15 JUL 201615 JUL 2016 HD-M-16-H-000001*1001*2 HD-M-16-H-000001*1001 HD-M-16-H-000001 15 JUL 201614 JUL 20170816AREBECCA SIOW SIQIN S1234567E 04 FEB 1995C O F- 15 JUL 201615 JUL 2016 HD-M-16-H-000001*1001*3 HD-M-16-H-000001*1001 HD-M-16-H-000001 15 JUL 201614 JUL 20170816ASAMANTHA SIOW SIHUI S1234567J 18 NOV 1993C O F- 15 JUL 201615 JUL 2016 "
My Text File is :
line 1:
HD-M-16-H-000001*1001*1 HD-M-16-H-000001*1001 HD-M-16-H-000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F- 15 JUL 201615 JUL 2016
line 2 :
HD-M-16-H-000001*1001*2 HD-M-16-H-000001*1001 HD-M-16-H-000001 15 JUL 201614 JUL 20170816AREBECCA SIOW SIQIN S1234567E 04 FEB 1995C O F- 15 JUL 201615 JUL 2016
Line 3:
HD-M-16-H-000001*1001*3 HD-M-16-H-000001*1001 HD-M-16-H-000001 15 JUL 201614 JUL 20170816ASAMANTHA SIOW SIHUI S1234567J 18 NOV 1993C O F- 15 JUL 201615 JUL 2016
So how can i show the json result with 3 (String) lines ?
Thanks in advance !!!
I have a string, named s respectively. The string s looks like :
"HD-M-16-H-000001*1001*1 HD-M-16-H-000001*1001 HD-M-16-H 000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F-
HD-M-16-H-000001*1001*2 HD-M-16-H-000001*1001 HD-M-16-H 000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F-
HD-M-16-H-000001*1001*3 HD-M-16-H-000001*1001 HD-M-16-H 000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F- "
I split the string based on rows. The code is
string s = sr.ReadToEnd();
string[] Mem = s.Split('\r');
So, Now the string[] Mem looks like :
"HD-M-16-H-000001*1001*1 HD-M-16-H-000001*1001 HD-M-16-H 000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F- "
"HD-M-16-H-000001*1001*2 HD-M-16-H-000001*1001 HD-M-16-H 000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F- "
"HD-M-16-H-000001*1001*3 HD-M-16-H-000001*1001 HD-M-16-H 000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F- "
Now, actually i am looking to create a dataTable with 'n' number of columns to hold Each word of each string in Mem.
The below code that takes each line of string[] and holds it into string. Then i split the string
string firststr = Mem.First();
string secondstr = Mem[1];
string thirdstr = Mem[2];
string str = firststr.Substring(0, 30);
string[] m = str.Split('\r');
Actually i want to store all the three string[] to one string datatype with 3 strings and split each line of string by substr using loop(foreach or While). So how can i acheive this???
Any help appreciated. Thanks in advance !!!!
My network only achieve around 80%, but the reported best score is around 85% accuracy. I m using same input data and same initalization. I dont know whats wrong, so I try to check my gradients and implemented what is recommended for gradient checking: http://ufldl.stanford.edu/tutorial/supervised/DebuggingGradientChecking/
But i m not sure, if my implementation is correct:
public void gradientchecking(double[] theta){
System.out.println("Gradient Checking started");
//costfunction returns cost and gradients
IPair<Double, double[]> org = costfunction(theta);
double[] theta_pos = new double[theta.length];
double[] theta_neg = new double[theta.length];
for (int i = 0; i < theta.length; i++) {
theta_pos[i]= theta[i];
theta_neg[i]=theta[i];
}
double mu = 1e-5;
for (int k = 0; k < 20; k++) {
theta_pos[k] = theta_pos[k] + mu;
theta_neg[k] = theta_neg[k] - mu;
IPair<Double, double[]> pos = costfunction(theta_pos);
IPair<Double, double[]> neg = costfunction(theta_neg);
System.out.println("Org: "+org.getSecond()[k] +" check:"+ ((pos.getSecond()[k]-neg.getSecond()[k])/(2*mu)));
//System.out.println("Org: "+org.getSecond()[k] +"check:"+ ((pos.getSecond()[k]-neg.getSecond()[k])/(2*mu)));
theta_pos[k] = theta_pos[k] - mu;
theta_neg[k] = theta_neg[k] + mu;
}
}
}
I got the following result after a freshly initialized theta:
Gradient Checking started
Cost: 1.1287071297725055 | Wrong: 124 | start: Thu Jul 30 22:57:08 CEST 2015 |end: Thu Jul 30 22:57:18 CEST 2015
Cost: 1.128707130295382 | Wrong: 124 | start: Thu Jul 30 22:57:18 CEST 2015 |end: Thu Jul 30 22:57:28 CEST 2015
Cost: 1.1287071292496391 | Wrong: 124 | start: Thu Jul 30 22:57:28 CEST 2015 |end: Thu Jul 30 22:57:38 CEST 2015
Org: 5.2287135944026004E-5 check:1.0184607936733826E-4
Cost: 1.1287071299252593 | Wrong: 124 | start: Thu Jul 30 22:57:38 CEST 2015 |end: Thu Jul 30 22:57:47 CEST 2015
Cost: 1.1287071296197628 | Wrong: 124 | start: Thu Jul 30 22:57:47 CEST 2015 |end: Thu Jul 30 22:57:56 CEST 2015
Org: 1.5274823511207024E-5 check:1.141254586229615E-4
Cost: 1.1287071299063134 | Wrong: 124 | start: Thu Jul 30 22:57:56 CEST 2015 |end: Thu Jul 30 22:58:05 CEST 2015
Cost: 1.1287071296387077 | Wrong: 124 | start: Thu Jul 30 22:58:05 CEST 2015 |end: Thu Jul 30 22:58:14 CEST 2015
Org: 1.3380293717695182E-5 check:1.0008639478696018E-4
Cost: 1.1287071297943114 | Wrong: 124 | start: Thu Jul 30 22:58:14 CEST 2015 |end: Thu Jul 30 22:58:23 CEST 2015
Cost: 1.1287071297507094 | Wrong: 124 | start: Thu Jul 30 22:58:23 CEST 2015 |end: Thu Jul 30 22:58:32 CEST 2015
Org: 2.1800899147740388E-6 check:9.980780136716263E-5
that indicates that my gradient calculation has an error, or the gradientchecking() method. I m not sure, can somebody help me?
In Java arrays are reference types.
int[] arr = { 8,7,6,5,4,3,2,1,8};
int[] b = arr;
b [0] = -10;
for (int i:arr) {
System.out.print (' ');
System.out.print (i);
}
outputs -10 7 6 5 4 3 2 1 8
So i mean that you incorrectly creating arrays
double[] theta_pos = theta;
double[] theta_neg = theta;
they are just references to theta, and by changing their contents you change theta also, +mu-mu = 0. Use clone() methods while copying array.
double[] theta_pos = theta.clone();
double[] theta_neg = theta.clone();
But remember that clone may not work as you expecting in some cases, with simple(non-reference) types it works ideal. Look at this
Does calling clone() on an array also clone its contents?
My iOS Simulator crashes when I try to use a UITapGestureRecognizer.
This is my Gesture:
UITapGestureRecognizer tap = new UITapGestureRecognizer (new NSAction(delegate {
if(SettingsTapped != null){
SettingsTapped(this, EventArgs.Empty);
}
}));
I am adding this Gesture to a UIView and then add this view to a UITableViewCell.
The App crashes after touching the View (every time), showing no Exception.
Her is a Output from the Simulator Log File:
Nov 4 10:49:47 administorsmini xXxXx[11073]: assertion failed: 13E28 12B411: libsystem_sim_trace.dylib + 19982 [BEE53863-0DEC-33B1-BFFB-8F7AE595CC73]: 0x4
Nov 4 10:49:49 administorsmini xXxXx[11073]: Stacktrace:
Nov 4 10:49:49 administorsmini xXxXx[11073]: at <unknown> <0xffffffff>
Nov 4 10:49:49 administorsmini xXxXx[11073]: at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x000a6, 0xffffffff>
Nov 4 10:49:49 administorsmini xXxXx[11073]: at MonoTouch.UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
Nov 4 10:49:49 administorsmini xXxXx[11073]: at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46
Nov 4 10:49:49 administorsmini xXxXx[11073]: at xXxXx.Application.Main (string[]) [0x00008] in /Users/Norman/Desktop/xXxXx/xXxXx/Main.cs:17
Nov 4 10:49:49 administorsmini xXxXx[11073]: at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
Nov 4 10:49:49 administorsmini xXxXx[11073]:
Native stacktrace:
Nov 4 10:49:49 administorsmini xXxXx[11073]:
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
Nov 4 10:49:49 administorsmini com.apple.CoreSimulator.SimDevice.27B5D497-B641-4BCA-8FA0-EF9E28E07143.launchd_sim[10951] (UIKitApplication:com.your-company.xXxXx[0x7041][11073]): Service exited due to signal: Abort trap: 6
Nov 4 10:49:49 administorsmini SpringBoard[10962]: Application 'UIKitApplication:com.your-company.xXxXx[0x7041]' crashed.
Nov 4 10:49:49 administorsmini assertiond[10966]: notify_suspend_pid() failed with error 7
Nov 4 10:49:49 administorsmini assertiond[10966]: assertion failed: 13E28 12B411: assertiond + 11523 [3F572A0B-7E12-378D-AFEE-EA491BAF2C36]: 0x1
What can I do now?
I don´t want to Develop on the Device...
EDIT
I ended up by overriding UIView and use its TouchesBegan() Method.
There are many approaches to make something clickable but why can´t I just use this one above??
Here's a bit of code that I'm using in my application:
private void addTapGesture()
{
imgLogo.UserInteractionEnabled = true;
var tapGesture = new UITapGestureRecognizer(this, new Selector("ResendTrigger:"));
tapGesture.NumberOfTapsRequired = 5;
imgLogo.AddGestureRecognizer(tapGesture);
}
[Export("ResendTrigger:")]
public void ResendTrigger(UIGestureRecognizer sender)
{
System.Diagnostics.Debug.WriteLine("Triggered");}
}
First argument of constructor (this) points to object that contains definition of method with specified Export attribute so if you will define selector and method inside your view NSObject target will be reference of your view if method that you want to call exist for example in cell your cell reference will be the target.EDITBased on comment I assumed that you may be using UITableViewSource . I think your case is similar to mine so try this approach :Declare event in your UITableSource something like public event EventHandler<DataBaseModels.SavedActions> OnActionSelected;Then in getCell assign tap gesture to your view and inside method you will have reference to sender objec, cast it to UIView and retain tag to identify corresponding record
Have any library solution to parse as follow file list string
0x001d8f60 "-rw------- 1 root root 000000000 Jun 30 2014 YS_LIANG
drw------- 1 root root 000000000 Jun 30 2014 2014-05-08 [][][] - [][][][]
drw------- 1 root root 000000000 Jun 30 2014 FTPClient-WinCE
drw------- 1 root root 000000000 Jun 30 2014 GRAPHIC
drw------- 1 root root 000000000 Jun 30 2014 S8521 V1.6.17
drw------- 1 root root 000000000 Jun 30 2014 S8521V1.7.0
drw------- 1 root root 000000000 Jun 30 2014 Storage Card2
drw------- 1 root root 000000000 Jun 30 2014 UltraEdit 18.20.0.1021
drw------- 1 root root 000000000 Jun 30 2014 usb wireless driver
drw------- 1 root root 000000000 Jun 30 2014 Windows7 ActiveSync
-rw------- 1 root root 101384240 Jun 28 2013 avira_free_antivirus_zhtw.exe
-rw------- 1 root root 000564736 Jun 21 2011 ComTest.exe
-rw------- 1 root root 000000189 Feb 10 2014 ComTest.INI
-rw------- 1 root root 006465536 May 5 2014 DR12AsyncSocket.exe
-r"
Thanks
ok, I got the solution.
while(true)
{
nNewLineIdx = strRespFileList.Find(_T("\r\n"));
if(nNewLineIdx == -1)
{
break;
}
// TODO : Save in CStringArray
}
// Parse CString line of CStringArray
for(int loop=0; loop<CStringArray.GetCount();loop++)
{
int strLineLen = CStringArray.GetAt(loop).GetLength();
int nSerchLoc = 0;
int nStep = 0;
while(nSerchLoc < strLineLen)
{
CString strTok = CStringArray.GetAt(loop).Tokenize(_T(" "), nSerchLoc);
// TODO : Save cut information
}
}