Getting memory leaks from Appcelerator Alloy app - appcelerator

I have an Alloy app. It has got 7 windows and opens at same time. When user close a opened window $.removeListener(); $.destroy(); codes runs at window close event. But I am getting memory leaks on Android device. %90 windows has got ListView, every window has got max 2 Listview. What is the right approach for multiple windows?

First of all, why you would want to open 7 windows at same time when user can only see max 1 window at a time.
It's dead simple, open only that window which user should see first, & create a link-flow to other window in previous window.
Can you think of any app on Play Store which does so, if you have, then please send me its link, I would really love to review it?
But if you mean to say that user will see all windows at same time in a scrolling behaviour or like paging, then go to Ti.UI.TabGroup

Are you 100% sure that your event listeners are being removed?
I don't know the function $.removeListener(); is this a custom function?
As a general rule I try and put as many of my event listeners into the xml, as these are automatically removed, and have a custom function destroyMe() that runs onClose which removes any other listeners that I may have used and $.destroy()
Ti.App.addEventListener is a killer too, make sure these are removed if you use them!
ps: i totally understand the 7 windows bit :-)

Related

Need to display a busy window on max with spinner

I'm a new Mac programmer writing my first mac app, actually porting an existing iOS app to MAC.
The app does a lot of remote communication, so when the user kicks off an operation, I want to display a busy window (or message box, or NSAlert maybe), until the operation is completed, then dismiss it programmatically, or the user can click cancel to stop it.
The busy window prevents the user from doing anything until that operation is completed.
The busy window should have a progress spinner, some text, and a cancel button.
Its such a simple thing yet I'm having problems with it because I dont really know MAC programming, getting myself frustrated.
Can anybody offer suggestions, or already written code for it. I hope some code for this already exists because I cant believe I'm the only person in the world who needs things kind of busy window.
Thanks for any help.
You mean something like this:
http://www.developers-life.com/example-nspanel-with-nsprogressindicator.html
???
Source code is available, too (link at the end of the article).
You can just modify the NSPanel in Xcode and add a "Cancel" button that you connect to your cancel action.

Running code when Chrome "opens" on a mac

I'm writing an extension that opens a tab when Chrome first runs, technically means placing code in the background page, which sounds simple enough, and works fine in Windows, and probably Linux as well, though I haven't tested it.
The problem is with Mac, which doesn't actually fully close Chrome when the user clicks the close button at the top left. To fully close Chrome you have to force quit it, which is something people generally do not do.
So this means I'll need to rely on some other event to trigger code when the user first "opens" chrome. Does anyone have idea for which even that could be? I suppose I could add a listener to every tab's create event and check the number of tabs, or something similar, but I'm looking for a light weight solution. Any ideas?
UPDATE: One idea us to use the chrome.windows.onCreated event and just check that there are no other windows open. Is that the best method, or can anyone think of something more efficient?
Use two events and a counter. Because window open/close are relatively rare, this should not be a problem:
onCreated, increase the counter, and validate the value.
onRemoved, decrease the counter.

Closing delphi app along with another application it opened

I have an application that called several other .exe components written in delphi. The question I ask is that is it possible to close the delphi app along with all application it opened (when clicking the '[x]' button)?
Also, obviously, I have learned how to open and close external application, but in several cases like Windows Media Player it just doesn't seem to work... can anyone give me some solution to this?
Thanks in advance
You can use Job Objects , read the documentation for these functions CreateJobObject and AssignProcessToJobObject.
A job object allows groups of processes to be managed as a unit....
Examples include enforcing limits such as working set size and process
priority or terminating all processes associated with a job.
If you keep track of the applications you open, you can post a WM_QUIT message to each one's window handle in the OnClose event of your Delphi app's main form.
The same should work for Media Player, but it's hard to say when you don't give any information about how you opened it.

wp7-how to make a thread navigate pages

I want to check for changes in the aplication state every time interval, and if it has changed, to open a window, and give the user 10 seconds to press on the window, if he does press on the window, then to allow him to navigate freely in the window, and if he doesn't press, to return back to the window before. I thought to implement it with a thread running in the background and waking up every time interval I want. Maybe there is a better way?
This strikes me as a scenario with lots of potential issues.
How do you stop the "window" appearing at an inconvenient time to the user? (e.g. when they were just about to tap on som.ething)
Why not just raise the notification when the state actually changes? This way you wouldn't need to poll.
What is the "Window" you are displaying? How does it differ from the page it is replacing? Is this a popup or are you actually navigating to a different page?
What is the state that's changing? How is it changing without user interaction?
Can't you notify the user of the state change without a potentially intrusive display of a new "window"?
I agree with #matt-lacey, this could be dangerous and might result in a bad user experience.
With that said, this might work
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
//navigation code here
});
I didn't know you could do a pop-up window, could you elaborate?
I've made a thread that is running at the background and making some work, if it decides that a change is necessary, I want to give the user a chance to react to it, or ignore it.
I'm pretty new to this, so if there is a better way than to navigate to a different page i would love to hear it.
Thanks.
It sounds to me like you want to notify the user that something has happened/changed and give them the option to do something about it, which is exactly what "toast" notifcations are all about. They pop up at the top of the screen to inform the user, and then the user can tap that toast to do something, e.g. when WiFi networks are available, you tap the toast to select an available network.
The Silverlight Windows Phone Toolkit includes the ToastRequestTrigger that you use to display toast notifications. The Windows Phone Developer Guide from the patterns & practices team gives examples of using the ToastRequestTrigger. You will need to implement the tap handling yourself in the toast content, but this should be simple enough.

take a screenshot of a desktop created using createdesktop api

i am using the createdesktop api to create a desktop and i would like to take a screenshot or send input mouse/keyboard without dispalying the desktop to the user.any ideeas on how to implement this???
The short answer that I've found is that you can't. You can't take a screenshot of an inactive desktop because there are no paint calls because there are no visible windows to redraw.
You can do a SwitchDesktop() call, screen shot, then SwitchDesktop() back. The user won't notice it, but you likely won't get much in the screen shot because in this short time the windows haven't had time to redraw.
Another thing is, you have to make a new thread to call SetThreadDesktop(). If you use your main thread to do so, it will fail when using a GUI application. SetThreadDesktop() fails when you have a window in the current desktop.
SysInternals has an application to manage multiple desktops (like the linux desktop switch). When your about to pick a desktop to switch to it will show you a thumbnail of the desktop. This thumbnail is not live, it is captured by the last known full redraw when the user is in that desktop. In short, if SysInternals can't do a live screenshot I doubt any of us will.
This is of course based on my own research of this exact feature. If someone has actually gotten it to work I'd love to know so I can't use it too!
Edit: This won't work for invisible desktops, I've looked to my old code, and I see that I needed that for catching screenshot of active desktop (which was not 'WinSta0\Default'), to get handle of active user desktop I've used OpenInputDesktop.
+1 ThievingSix you are right.
Sorry everyone for my misunderstanding.
You need to use SetThreadDesktop (if you are creating desktop by CreateDestkop, then you have handle for it which you pass to SetThreadDesktop). After switching desktop for thread, you can catch screenshot. Good idea would be revert to previous desktop for thread (to not 'break' other/future code).
var
lOldDesktop: HDESK;
begin
lOldDesktop:= GetThreadDesktop(GetCurrentThreadId);
try
if not SetThreadDesktop(ADesktop) then // pass handle to your desktop, or dekstop handle obtained from OpenInputDesktop
{error handle, like RaiseLastOSError or Exit(False)};
// your screenshot/input/mouse code here
finally
if lOldDesktop<> 0 then // GetThreadDesktop can fail (I don't know condition when this GetThreadDesktop(GetCurrentThreadId) could fail)
SetThreadDesktop(lOldDesktop); // revert thread to previous desktop
end;
end;
This code should run in non-main thread, as ThievingSix pointed because SetThreadDesktop can fail in that case. Safe way is spawn thread to make screenshot.
PS. I'm not sure if this will work with "send input mouse/keyboard" (it should), but for screenshot works.
Edit:
More on sessions, window stations, desktops here http://blogs.technet.com/b/askperf/archive/2007/07/24/sessions-desktops-and-windows-stations.aspx
Desktop tool (SysInternals) - http://technet.microsoft.com/en-us/sysinternals/cc817881

Resources