Delete uiprogress object at the end of startup function

6 views (last 30 days)
Hello,
It seems that MATLAB is not deleting the uiprogress object variable when startup function in App Designer apps ends execution.
  • Does it behave differently for some local variables? I do now delete or close (pBar), but why bother when it is local variable?
function startupFcn(app)
pBar = Utility.showIndeterminateBar(app.UIFigure);
%.....
end
%... Still runs....
UPDATE 1
I tested a separate app, and it the correct behaviour operated but not with actual. Though I have tested it with above code, removed the Utility function so that you can test...though there is nothing...
UPDATE 2
Tested with onCleanup, the result is the same...I can conclude that this has to do with MATLAB not clearing the startupFcn on time/immediately...The question would be; is there anything that can be done to prevent this?
function onCleanUpTask = showIndeterminateBar(uifigObj)
uiprogbar = uiprogressdlg(uifigObj,'Title','Please Wait...',"Indeterminate","on");
onCleanUpTask = onCleanup(@()delete(uiprogbar));
end
For your full knowledge I do have:
app.onCleanupArray{1} = onCleanup(@()cleanUpTasks(ParamNumberIn));
ParamNumberIn is a param variable local to startupFcn which will be deleted when the UIFigure is deleted. Which maybe the cause that MATLAB is saving the WORKSPACE for that function because this referenced local variable?
  6 Comments
Adam Danz
Adam Danz on 14 Apr 2020
Edited: Adam Danz on 14 Apr 2020
I assumed that the progress bar you're describing is produced in Utility.showIndeterminateBar (based on the variable name and that it's called from the startupFcn) but I don't know what that function is.
AppDesigner doesn't show a progress bar when opening the app unless you've programmed one, so the source of the progress bar is unclear.
When opening the app for editing, a progress bar is shown (example below). Is this was you're referring to?
Bereketab Gulai
Bereketab Gulai on 14 Apr 2020
Sorry,
I meant that
`Utility.showIndeterminateBar`
From my project was a cover function. It just returns uiprogressdlg object and I tested it with the example I have attached it works fine.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 14 Apr 2020
The uiprogressdlg outputs a handle to the progress bar. To delete the bar,
d = uiprogressdlg(h);
delete(d)
to reset it to 0,
d.Value = 0;
If it works when you use the uiprogressbar directly but it doesn't work when you use your wrapper function, my guess is that you're not providing the correct handle to the uiprogressbar in the output.
When you try to delete it, is there an error?
If the problem persists, please provide the entire wrapper function so we can see what's going on and share any error messages in their entirety.
  3 Comments
Adam Danz
Adam Danz on 15 Apr 2020
Why not just run uiprogressdlg independently? Why wrap it in another function?
I suggest the following:
1) Set the uiprogbar handle as a private property of your app. To do so, follow step #2 described here.
2) In your startup function, call uiprogressdlg directly. The handle to the progress bar will be stored in the app variable and will be accessible from anywhere within the app where the app variable is accessed.
app.uiprogbar = uiprogressdlg(uifigObj,'Title','Please Wait...',"Indeterminate","on");
3) whenever you want to delete the progress bar,
delete(app.uiprogbar)
Bereketab Gulai
Bereketab Gulai on 16 Apr 2020
Hi Adam,
Thank you for the comment.
  1. My project is bigger than one uifigure.
  2. There is no point in storing the uiprogressdlg object, since it needs to be deleted and recreated in each use. It cannot be stored as constant or private variable because a running uifigure is required.
  3. To meet those conditions, it can be put in a wrapper function and called whenever needed providing the running uifigure handle. This solution works perfectly, the only problem of my discussion was that "the lack of imporance of doing delete(pBar) when the pBar is local to the function thus should be deleted automatically...at the end of the function.".
To conclude, the problem is with that the whole workspace for that function is saved because other variables are referenced. This discussion should probably be moved to "MATLAB support/bug centre", because this rule (Object Lifecycle), I think is not meet for this PARTICULAR variable (pBar) ("No longer referenced anywhere").

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!