freeze #658
Replies: 4 comments 4 replies
-
The questions "can I freeze x" and "can I preload x" are very different questions :) Freezing is something you do to JavaScript objects. Preloading is something you do to a JavaScript module. Correct me if I'm wrong, but it looks like you've already determined that you can freeze the To answer that question: no, you can't preload a module that instantiates Piu objects (like scrollers, labels, styles, etc.). For example, say your const BlueBox = new Content(null, {
top: 0, bottom: 0, left: 0, right: 0,
skin: new Skin({ fill: "blue" })
});
export default new Application(null, {
contents: [
BlueBox
]
}); You can, however, write this module in a way that can be preloaded. For example, you can put the code that instantiates the export default function() {
const BlueBox = new Content(null, {
top: 0, bottom: 0, left: 0, right: 0,
skin: new Skin({ fill: "blue" })
});
return new Application(null, {
contents: [
BlueBox
]
});
} Piu templates are also a useful tool that you can use to make modules preloadable. The const BlueSkin = Skin.template({ fill: "blue" });
const BlueBox = Content.template($ => ({
top: 0, bottom: 0, left: 0, right: 0,
Skin: BlueSkin
}));
const BlueApp = Application.template($ => ({
contents: [
new BlueBox($)
]
}));
export default function() {
return new BlueApp;
} So, to summarize:
|
Beta Was this translation helpful? Give feedback.
-
Dear Lizzie,
I have a questions |
Beta Was this translation helpful? Give feedback.
-
@mauroForlimpopoli, you are asking complex questions but providing few details. You are assuming that preload will solve your memory problem. It might, but that depends on what is using memory. For example, a complex UI with instances of many objects requires memory and that preload cannot help with. Some notes:
|
Beta Was this translation helpful? Give feedback.
-
You may be confusing the freezing of an object with preload. Freezing an object prevents modification of existing properties and adding new properties. That is defined by the JavaScript language. Preloading of modules is a feature of the XS JavaScript engine. It allows the body of a modules to be executed at build time on your computer, rather than at runtime on the device. Objects that are frozen during preload may be stored in flash memory, so they don't use RAM on the device. You show examples of code that you are stepping through on the device in xsbug. That is after preload has finished. The code is running on the device. Objects created at runtime on the device use memory, even if you freeze them. Consider this example you give:
You note that it is consuming 256 bytes of slots. That is expected, because you are initializing the object on the device. The To move those 256 bytes to flash memory, the
|
Beta Was this translation helpful? Give feedback.
-
I done a scroller. This is the code:
I freezed the VerticalScrollerBehavior and ScrollerActBehavior,
Can I freeze it or preload the scroller like I done ?
Regards
regards
Beta Was this translation helpful? Give feedback.
All reactions